[machineid] Drop namespace to avoid lupdate warnings

This commit is contained in:
Adriaan de Groot 2023-12-27 00:41:03 +01:00
parent 0ac170c3de
commit 93ce2daff0
5 changed files with 24 additions and 33 deletions

View File

@ -23,13 +23,13 @@
#include <QFile> #include <QFile>
const NamedEnumTable< MachineId::SystemdMachineIdStyle >& const NamedEnumTable< SystemdMachineIdStyle >&
styleNames() styleNames()
{ {
using T = MachineId::SystemdMachineIdStyle; using T = SystemdMachineIdStyle;
// *INDENT-OFF* // *INDENT-OFF*
// clang-format off // clang-format off
static const NamedEnumTable< MachineId::SystemdMachineIdStyle > names { static const NamedEnumTable< SystemdMachineIdStyle > names {
{ QStringLiteral( "none" ), T::Blank }, { QStringLiteral( "none" ), T::Blank },
{ QStringLiteral( "blank" ), T::Blank }, { QStringLiteral( "blank" ), T::Blank },
{ QStringLiteral( "uuid" ), T::Uuid }, { QStringLiteral( "uuid" ), T::Uuid },
@ -101,8 +101,8 @@ MachineIdJob::exec()
QObject::tr( "Directory not found" ), QObject::tr( "Directory not found" ),
QObject::tr( "Could not create new random file <pre>%1</pre>." ).arg( entropy_file ) ); QObject::tr( "Could not create new random file <pre>%1</pre>." ).arg( entropy_file ) );
} }
auto r = MachineId::createEntropy( m_entropy_copy ? MachineId::EntropyGeneration::CopyFromHost auto r = createEntropy( m_entropy_copy ? EntropyGeneration::CopyFromHost
: MachineId::EntropyGeneration::New, : EntropyGeneration::New,
root, root,
entropy_file ); entropy_file );
if ( !r ) if ( !r )
@ -116,7 +116,7 @@ MachineIdJob::exec()
{ {
cWarning() << "Could not create systemd data-directory."; cWarning() << "Could not create systemd data-directory.";
} }
auto r = MachineId::createSystemdMachineId( m_systemd_style, root, target_systemd_machineid_file ); auto r = createSystemdMachineId( m_systemd_style, root, target_systemd_machineid_file );
if ( !r ) if ( !r )
{ {
return r; return r;
@ -130,7 +130,7 @@ MachineIdJob::exec()
} }
if ( m_dbus_symlink && QFile::exists( root + target_systemd_machineid_file ) ) if ( m_dbus_symlink && QFile::exists( root + target_systemd_machineid_file ) )
{ {
auto r = MachineId::createDBusLink( root, target_dbus_machineid_file, target_systemd_machineid_file ); auto r = createDBusLink( root, target_dbus_machineid_file, target_systemd_machineid_file );
if ( !r ) if ( !r )
{ {
return r; return r;
@ -138,7 +138,7 @@ MachineIdJob::exec()
} }
else else
{ {
auto r = MachineId::createDBusMachineId( root, target_dbus_machineid_file ); auto r = createDBusMachineId( root, target_dbus_machineid_file );
if ( !r ) if ( !r )
{ {
return r; return r;
@ -157,7 +157,7 @@ MachineIdJob::setConfigurationMap( const QVariantMap& map )
const auto style = Calamares::getString( map, "systemd-style", QString() ); const auto style = Calamares::getString( map, "systemd-style", QString() );
if ( !style.isEmpty() ) if ( !style.isEmpty() )
{ {
m_systemd_style = styleNames().find( style, MachineId::SystemdMachineIdStyle::Uuid ); m_systemd_style = styleNames().find( style, SystemdMachineIdStyle::Uuid );
} }
m_dbus = Calamares::getBool( map, "dbus", false ); m_dbus = Calamares::getBool( map, "dbus", false );
@ -179,7 +179,7 @@ MachineIdJob::setConfigurationMap( const QVariantMap& map )
m_entropy_files = Calamares::getStringList( map, "entropy-files" ); m_entropy_files = Calamares::getStringList( map, "entropy-files" );
if ( Calamares::getBool( map, "entropy", false ) ) if ( Calamares::getBool( map, "entropy", false ) )
{ {
cWarning() << "MachineId:: configuration setting *entropy* is deprecated, use *entropy-files* instead."; cWarning() << " configuration setting *entropy* is deprecated, use *entropy-files* instead.";
m_entropy_files.append( QStringLiteral( "/var/lib/urandom/random-seed" ) ); m_entropy_files.append( QStringLiteral( "/var/lib/urandom/random-seed" ) );
} }
m_entropy_files.removeDuplicates(); m_entropy_files.removeDuplicates();

View File

@ -48,7 +48,7 @@ public:
private: private:
bool m_systemd = false; ///< write systemd's files bool m_systemd = false; ///< write systemd's files
MachineId::SystemdMachineIdStyle m_systemd_style = MachineId::SystemdMachineIdStyle::Uuid; SystemdMachineIdStyle m_systemd_style = SystemdMachineIdStyle::Uuid;
bool m_dbus = false; ///< write dbus files bool m_dbus = false; ///< write dbus files
bool m_dbus_symlink = false; ///< .. or just symlink to systemd bool m_dbus_symlink = false; ///< .. or just symlink to systemd

View File

@ -127,18 +127,18 @@ MachineIdTests::testCopyFile()
QVERIFY( source.exists() ); QVERIFY( source.exists() );
// This should fail since "example" isn't standard in our test directory // This should fail since "example" isn't standard in our test directory
auto r0 = MachineId::copyFile( tempRoot.path(), "example" ); auto r0 = copyFile( tempRoot.path(), "example" );
QVERIFY( !r0 ); QVERIFY( !r0 );
const QString sampleFile = QStringLiteral( "CMakeCache.txt" ); const QString sampleFile = QStringLiteral( "CMakeCache.txt" );
if ( QFile::exists( sampleFile ) ) if ( QFile::exists( sampleFile ) )
{ {
auto r1 = MachineId::copyFile( tempRoot.path(), sampleFile ); auto r1 = copyFile( tempRoot.path(), sampleFile );
// Also fail, because it's not an absolute path // Also fail, because it's not an absolute path
QVERIFY( !r1 ); QVERIFY( !r1 );
QVERIFY( QFile::copy( sampleFile, tempISOdir.path() + '/' + sampleFile ) ); QVERIFY( QFile::copy( sampleFile, tempISOdir.path() + '/' + sampleFile ) );
auto r2 = MachineId::copyFile( tempRoot.path(), tempISOdir.path() + '/' + sampleFile ); auto r2 = copyFile( tempRoot.path(), tempISOdir.path() + '/' + sampleFile );
QVERIFY( r2 ); QVERIFY( r2 );
} }
} }

View File

@ -12,6 +12,8 @@
#include "Workers.h" #include "Workers.h"
#include "MachineIdJob.h"
#include "utils/Entropy.h" #include "utils/Entropy.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/System.h" #include "utils/System.h"
@ -46,9 +48,6 @@ getUrandomPoolSize()
return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize; return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize;
} }
namespace MachineId
{
static inline bool static inline bool
isAbsolutePath( const QString& fileName ) isAbsolutePath( const QString& fileName )
{ {
@ -61,19 +60,19 @@ copyFile( const QString& rootMountPoint, const QString& fileName )
if ( !isAbsolutePath( fileName ) ) if ( !isAbsolutePath( fileName ) )
{ {
return Calamares::JobResult::internalError( return Calamares::JobResult::internalError(
QObject::tr( "File not found" ), MachineIdJob::tr( "File not found" ),
QObject::tr( "Path <pre>%1</pre> must be an absolute path." ).arg( fileName ), MachineIdJob::tr( "Path <pre>%1</pre> must be an absolute path." ).arg( fileName ),
0 ); 0 );
} }
QFile f( fileName ); QFile f( fileName );
if ( !f.exists() ) if ( !f.exists() )
{ {
return Calamares::JobResult::error( QObject::tr( "File not found" ), fileName ); return Calamares::JobResult::error( MachineIdJob::tr( "File not found" ), fileName );
} }
if ( !f.copy( rootMountPoint + fileName ) ) if ( !f.copy( rootMountPoint + fileName ) )
{ {
return Calamares::JobResult::error( QObject::tr( "File not found" ), rootMountPoint + fileName ); return Calamares::JobResult::error( MachineIdJob::tr( "File not found" ), rootMountPoint + fileName );
} }
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
} }
@ -90,8 +89,8 @@ createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fi
if ( !entropyFile.open( QIODevice::WriteOnly ) ) if ( !entropyFile.open( QIODevice::WriteOnly ) )
{ {
return Calamares::JobResult::error( return Calamares::JobResult::error(
QObject::tr( "File not found" ), MachineIdJob::tr( "File not found" ),
QObject::tr( "Could not create new random file <pre>%1</pre>." ).arg( fileName ) ); MachineIdJob::tr( "Could not create new random file <pre>%1</pre>." ).arg( fileName ) );
} }
QByteArray data; QByteArray data;
@ -190,5 +189,3 @@ createDBusLink( const QString& rootMountPoint, const QString& fileName, const QS
Q_UNUSED( rootMountPoint ) Q_UNUSED( rootMountPoint )
return runCmd( QStringList { QStringLiteral( "ln" ), QStringLiteral( "-sf" ), systemdFileName, fileName }, true ); return runCmd( QStringList { QStringLiteral( "ln" ), QStringLiteral( "-sf" ), systemdFileName, fileName }, true );
} }
} // namespace MachineId

View File

@ -7,14 +7,11 @@
* *
*/ */
#ifndef WORKERS_H #ifndef MACHINEID_WORKERS_H
#define WORKERS_H #define MACHINEID_WORKERS_H
#include "Job.h" #include "Job.h"
/// @brief Utility functions for doing the random-data stuff for MachineId
namespace MachineId
{
/** @brief Utility functions /** @brief Utility functions
* *
* These probably belong in libcalamares, since they're general utilities * These probably belong in libcalamares, since they're general utilities
@ -70,7 +67,4 @@ enum class SystemdMachineIdStyle
Calamares::JobResult Calamares::JobResult
createSystemdMachineId( SystemdMachineIdStyle style, const QString& rootMountPoint, const QString& fileName ); createSystemdMachineId( SystemdMachineIdStyle style, const QString& rootMountPoint, const QString& fileName );
} // namespace MachineId
#endif // WORKERS_H #endif // WORKERS_H