From 537aad1222a1676163848e2b6ed1d9af2c383c1a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 8 Aug 2020 23:32:09 +0200 Subject: [PATCH 1/2] [libcalamares] SPDX, DLLEXPORT on partition/FileSystem.h --- src/libcalamares/partition/FileSystem.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcalamares/partition/FileSystem.h b/src/libcalamares/partition/FileSystem.h index a683aab47..6f058fd81 100644 --- a/src/libcalamares/partition/FileSystem.h +++ b/src/libcalamares/partition/FileSystem.h @@ -1,8 +1,9 @@ /* === This file is part of Calamares - === - * + * * SPDX-FileCopyrightText: 2014 Aurélien Gâteau * SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac * SPDX-FileCopyrightText: 2019 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,9 +18,6 @@ * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . * - * SPDX-License-Identifier: GPL-3.0-or-later - * License-Filename: LICENSE - * */ /* @@ -30,13 +28,15 @@ #ifndef PARTITION_FILESYSTEM_H #define PARTITION_FILESYSTEM_H +#include "DllMacro.h" + #include namespace CalamaresUtils { namespace Partition { -QString prettyNameForFileSystemType( FileSystem::Type t ); +QString DLLEXPORT prettyNameForFileSystemType( FileSystem::Type t ); static inline QString untranslatedFS( FileSystem& fs ) From 62a8ee9708ab1da451681187d2edeca34671e5ab Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 9 Aug 2020 00:00:14 +0200 Subject: [PATCH 2/2] [libcalamares] Add name-for-partition-type method - add apidox to all the untranslatedFS() methods - add the most-basic of untranslatedFS(), which works on a given FileSystem::Type; this one can handle special cases where Cala needs a different untranslated name than what KPMCore provides. --- src/libcalamares/partition/FileSystem.cpp | 14 +++++++++++- src/libcalamares/partition/FileSystem.h | 20 ++++++++++++++++- src/libcalamares/partition/KPMTests.cpp | 26 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/partition/FileSystem.cpp b/src/libcalamares/partition/FileSystem.cpp index 965a1a8af..6fda6b41a 100644 --- a/src/libcalamares/partition/FileSystem.cpp +++ b/src/libcalamares/partition/FileSystem.cpp @@ -1,5 +1,5 @@ /* === This file is part of Calamares - === - * + * * SPDX-FileCopyrightText: 2014 Aurélien Gâteau * SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac * SPDX-FileCopyrightText: 2018-2019 Adriaan de Groot @@ -74,5 +74,17 @@ prettyNameForFileSystemType( FileSystem::Type t ) } } +QString +untranslatedFS( FileSystem::Type t ) +{ + switch ( t ) + { + case FileSystem::Type::ReiserFS: + return QStringLiteral( "reiserfs" ); + default: + return FileSystem::nameForType( t, { QStringLiteral( "C" ) } ); + } +} + } // namespace Partition } // namespace CalamaresUtils diff --git a/src/libcalamares/partition/FileSystem.h b/src/libcalamares/partition/FileSystem.h index 6f058fd81..03f6ff3bc 100644 --- a/src/libcalamares/partition/FileSystem.h +++ b/src/libcalamares/partition/FileSystem.h @@ -38,12 +38,30 @@ namespace Partition { QString DLLEXPORT prettyNameForFileSystemType( FileSystem::Type t ); +/** @brief Returns a machine-readable identifier for the filesystem type + * + * This identifier is used in filesystem manipulation -- + * e.g. when mounting the filesystem, or in /etc/fstab. It + * is almost always just what KPMCore says it is, with + * the following exceptions: + * - reiserfs is called "reiser" by KPMCore, "reiserfs" by Calamares + */ +QString DLLEXPORT untranslatedFS( FileSystem::Type t ); + +/** @brief Returns the machine-readable identifier for the given @p fs + * + * See notes for untranslatedFS(), above. + */ static inline QString untranslatedFS( FileSystem& fs ) { - return fs.name( { QStringLiteral( "C" ) } ); + return untranslatedFS( fs.type() ); } +/** @brief Returns a machine-readable identifier for the given @p fs + * + * Returns an empty string is the @p fs is not valid (e.g. nullptr). + */ static inline QString untranslatedFS( FileSystem* fs ) { diff --git a/src/libcalamares/partition/KPMTests.cpp b/src/libcalamares/partition/KPMTests.cpp index ed34c2701..d702c8a01 100644 --- a/src/libcalamares/partition/KPMTests.cpp +++ b/src/libcalamares/partition/KPMTests.cpp @@ -20,6 +20,8 @@ #include "utils/Logger.h" +#include "FileSystem.h" + #include #include @@ -100,6 +102,30 @@ KPMTests::testFSNames() QVERIFY( fsNames.contains( "ext2" ) ); QVERIFY( fsNames.contains( "ext4" ) ); QVERIFY( fsNames.contains( "reiser" ) ); + + QStringList calaFSNames; + calaFSNames.reserve( fstypes.count() ); + for ( const auto t : fstypes ) + { + QString s = CalamaresUtils::Partition::untranslatedFS( t ); + calaFSNames.append( s ); + } + + QVERIFY( calaFSNames.contains( "ext2" ) ); + QVERIFY( calaFSNames.contains( "ext4" ) ); + QVERIFY( !calaFSNames.contains( "reiser" ) ); + QVERIFY( calaFSNames.contains( "reiserfs" ) ); // whole point of Cala's own implementation + + // Lists are the same except for .. the exceptions + QStringList exceptionalNames { "reiser", "reiserfs" }; + for ( const auto& s : fsNames ) + { + QVERIFY( exceptionalNames.contains( s ) || calaFSNames.contains( s ) ); + } + for ( const auto& s : calaFSNames ) + { + QVERIFY( exceptionalNames.contains( s ) || fsNames.contains( s ) ); + } }