[machineid] Migrate removeFile() to libcalamares
- Becomes removeTargetFile()
This commit is contained in:
parent
9ef04192db
commit
bf882cec1d
@ -1,7 +1,7 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2017-2018, 2020, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -285,6 +285,13 @@ System::targetPath( const QString& path ) const
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Cheap check if a path is absolute.
|
||||
static inline bool
|
||||
isAbsolutePath( const QString& path )
|
||||
{
|
||||
return path.startsWith( '/' );
|
||||
}
|
||||
|
||||
QString
|
||||
System::createTargetFile( const QString& path, const QByteArray& contents ) const
|
||||
{
|
||||
@ -323,6 +330,17 @@ System::createTargetFile( const QString& path, const QByteArray& contents ) cons
|
||||
return QFileInfo( f ).canonicalFilePath();
|
||||
}
|
||||
|
||||
void
|
||||
System::removeTargetFile( const QString& path ) const
|
||||
{
|
||||
if ( !isAbsolutePath( path ) )
|
||||
{
|
||||
cWarning() << "Will not remove non-absolute path" << path;
|
||||
return;
|
||||
}
|
||||
QFile::remove( targetPath( path ) );
|
||||
}
|
||||
|
||||
|
||||
QPair< quint64, float >
|
||||
System::getTotalMemoryB() const
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2017-2018, 2020, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -246,6 +246,15 @@ public:
|
||||
*/
|
||||
DLLEXPORT QString createTargetFile( const QString& path, const QByteArray& contents ) const;
|
||||
|
||||
/** @brief Remove a file from the target system.
|
||||
*
|
||||
* @param path Path to the file; this is interpreted from the root
|
||||
* of the target system (@see targetPath()).
|
||||
*
|
||||
* Does no error checking to see if the target file was really removed.
|
||||
*/
|
||||
DLLEXPORT void removeTargetFile( const QString& path ) const;
|
||||
|
||||
/**
|
||||
* @brief getTotalMemoryB returns the total main memory, in bytes.
|
||||
*
|
||||
|
@ -3,7 +3,7 @@
|
||||
* Copyright 2014, Kevin Kofler <kevin.kofler@chello.at>
|
||||
* Copyright 2016, Philip Müller <philm@manjaro.org>
|
||||
* Copyright 2017, Alf Gaida <agaida@siduction.org>
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -68,18 +68,20 @@ MachineIdJob::exec()
|
||||
QString target_dbus_machineid_file = QStringLiteral( "/var/lib/dbus/machine-id" );
|
||||
QString target_entropy_file = QStringLiteral( "/var/lib/urandom/random-seed" );
|
||||
|
||||
const auto* system = CalamaresUtils::System::instance();
|
||||
|
||||
// Clear existing files
|
||||
if ( m_entropy )
|
||||
{
|
||||
MachineId::removeFile( root, target_entropy_file );
|
||||
system->removeTargetFile( target_entropy_file );
|
||||
}
|
||||
if ( m_dbus )
|
||||
{
|
||||
MachineId::removeFile( root, target_dbus_machineid_file );
|
||||
system->removeTargetFile( target_dbus_machineid_file );
|
||||
}
|
||||
if ( m_systemd )
|
||||
{
|
||||
MachineId::removeFile( root, target_systemd_machineid_file );
|
||||
system->removeTargetFile( target_systemd_machineid_file );
|
||||
}
|
||||
|
||||
//Create new files
|
||||
|
@ -36,17 +36,6 @@ isAbsolutePath( const QString& fileName )
|
||||
return fileName.startsWith( '/' );
|
||||
}
|
||||
|
||||
// might need to use a helper to remove the file
|
||||
void
|
||||
removeFile( const QString& rootMountPoint, const QString& fileName )
|
||||
{
|
||||
if ( isAbsolutePath( fileName ) )
|
||||
{
|
||||
QFile::remove( rootMountPoint + fileName );
|
||||
}
|
||||
// Otherwise, do nothing
|
||||
}
|
||||
|
||||
Calamares::JobResult
|
||||
copyFile( const QString& rootMountPoint, const QString& fileName )
|
||||
{
|
||||
|
@ -30,9 +30,6 @@ namespace MachineId
|
||||
* for moving files around in the target system.
|
||||
*/
|
||||
|
||||
/// @brief Remove @p fileName from the target system at @p rootMountPoint
|
||||
void removeFile( const QString& rootMountPoint, const QString& fileName );
|
||||
|
||||
/// @brief Copy @p fileName from host into target system at @p rootMountPoint
|
||||
Calamares::JobResult copyFile( const QString& rootMountPoint, const QString& fileName );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user