mirror of https://github.com/cutefishos/calamares
commit
7e8ef85dc9
@ -0,0 +1,56 @@
|
|||||||
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
|
#include <QVariantMap>
|
||||||
|
|
||||||
|
static const QString fsUse_key = QStringLiteral( "filesystem_use" );
|
||||||
|
|
||||||
|
bool
|
||||||
|
CalamaresUtils::Partition::isFilesystemUsedGS( const Calamares::GlobalStorage* gs, const QString& filesystemType )
|
||||||
|
{
|
||||||
|
if ( !gs )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const QVariantMap fsUse = gs->value( fsUse_key ).toMap();
|
||||||
|
QString key = filesystemType.toLower();
|
||||||
|
if ( fsUse.contains( key ) )
|
||||||
|
{
|
||||||
|
const auto v = fsUse.value( key );
|
||||||
|
return v.toBool();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CalamaresUtils::Partition::useFilesystemGS( Calamares::GlobalStorage* gs, const QString& filesystemType, bool used )
|
||||||
|
{
|
||||||
|
if ( gs )
|
||||||
|
{
|
||||||
|
QVariantMap existingMap = gs->contains( fsUse_key ) ? gs->value( fsUse_key ).toMap() : QVariantMap();
|
||||||
|
QString key = filesystemType.toLower();
|
||||||
|
existingMap.insert( key, used );
|
||||||
|
gs->insert( fsUse_key, existingMap );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CalamaresUtils::Partition::clearFilesystemGS( Calamares::GlobalStorage* gs )
|
||||||
|
{
|
||||||
|
if ( gs )
|
||||||
|
{
|
||||||
|
gs->remove( fsUse_key );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*
|
||||||
|
* Calamares is Free Software: see the License-Identifier above.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is the API for manipulating Global Storage keys related to
|
||||||
|
* filesystems and partitions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PARTITION_GLOBAL_H
|
||||||
|
#define PARTITION_GLOBAL_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
|
#ifdef WITH_KPMCORE4API
|
||||||
|
#include "FileSystem.h"
|
||||||
|
|
||||||
|
#include <kpmcore/fs/filesystem.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
namespace Partition
|
||||||
|
{
|
||||||
|
/** @brief Mark a particular filesystem type as used (or not)
|
||||||
|
*
|
||||||
|
* Filesystems are marked used (or not) in the global storage
|
||||||
|
* key *filesystem_use*. Sub-keys are the filesystem name,
|
||||||
|
* and the values are boolean; filesystems that are used in
|
||||||
|
* the target system are marked with @c true. Unused filesystems
|
||||||
|
* may be unmarked, or may be marked @c false.
|
||||||
|
*
|
||||||
|
* The filesystem name should be the untranslated name. Filesystem
|
||||||
|
* names are **lower**cased when used as keys.
|
||||||
|
*/
|
||||||
|
void DLLEXPORT useFilesystemGS( Calamares::GlobalStorage* gs, const QString& filesystemType, bool used );
|
||||||
|
/** @brief Reads from global storage whether the filesystem type is used
|
||||||
|
*
|
||||||
|
* Reads from the global storage key *filesystem_use* and returns
|
||||||
|
* the boolean value stored in subkey @p filesystemType. Returns
|
||||||
|
* @c false if the subkey is not set at all.
|
||||||
|
*
|
||||||
|
* The filesystem name should be the untranslated name. Filesystem
|
||||||
|
* names are **lower**cased when used as keys.
|
||||||
|
*/
|
||||||
|
bool DLLEXPORT isFilesystemUsedGS( const Calamares::GlobalStorage* gs, const QString& filesystemType );
|
||||||
|
|
||||||
|
/** @brief Clears the usage data for filesystems
|
||||||
|
*
|
||||||
|
* This removes the internal key *filesystem_use*.
|
||||||
|
*/
|
||||||
|
void DLLEXPORT clearFilesystemGS( Calamares::GlobalStorage* gs );
|
||||||
|
|
||||||
|
/** @brief Convenience function for using "the" Global Storage
|
||||||
|
*
|
||||||
|
* @see useFilesystemGS(const QString&, bool)
|
||||||
|
*/
|
||||||
|
inline void
|
||||||
|
useFilesystemGS( const QString& filesystemType, bool used )
|
||||||
|
{
|
||||||
|
useFilesystemGS( Calamares::JobQueue::instanceGlobalStorage(), filesystemType, used );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Convenience function for using "the" Global Storage
|
||||||
|
*
|
||||||
|
* @see isFilesystemUsedGS(const QString&);
|
||||||
|
*/
|
||||||
|
inline bool
|
||||||
|
isFilesystemUsedGS( const QString& filesystemType )
|
||||||
|
{
|
||||||
|
return isFilesystemUsedGS( Calamares::JobQueue::instanceGlobalStorage(), filesystemType );
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef WITH_KPMCORE4API
|
||||||
|
/** @brief Mark a particular filesystem type as used (or not)
|
||||||
|
*
|
||||||
|
* See useFilesystemGS(const QString&, bool); this method uses the filesystem type
|
||||||
|
* enumeration to pick the name.
|
||||||
|
*/
|
||||||
|
inline void
|
||||||
|
useFilesystemGS( FileSystem::Type filesystem, bool used )
|
||||||
|
{
|
||||||
|
useFilesystemGS( untranslatedFS( filesystem ), used );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @brief Reads from global storage whether the typesystem type is used
|
||||||
|
*
|
||||||
|
* See isFilesystemUsedGS(const QString&).
|
||||||
|
*/
|
||||||
|
inline bool
|
||||||
|
isFilesystemUsedGS( FileSystem::Type filesystem )
|
||||||
|
{
|
||||||
|
return isFilesystemUsedGS( untranslatedFS( filesystem ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
} // namespace Partition
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif
|
@ -1,33 +0,0 @@
|
|||||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
|
||||||
*
|
|
||||||
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* Calamares is Free Software: see the License-Identifier above.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBCALAMARES_PARTITION_TESTS_H
|
|
||||||
#define LIBCALAMARES_PARTITION_TESTS_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class PartitionSizeTests : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
PartitionSizeTests();
|
|
||||||
~PartitionSizeTests() override;
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void initTestCase();
|
|
||||||
|
|
||||||
void testUnitComparison_data();
|
|
||||||
void testUnitComparison();
|
|
||||||
|
|
||||||
void testUnitNormalisation_data();
|
|
||||||
void testUnitNormalisation();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue