LibrePCB Developers Documentation
|
Transactional librepcb::FileSystem implementation. More...
#include <transactionalfilesystem.h>
Classes | |
struct | RestoreMode |
Convenience class providing standard implementations for librepcb::TransactionalFileSystem::RestoreCallback. More... | |
Public Types | |
typedef std::function< bool(const QString &filePath)> | FilterFunction |
Function to filter files. More... | |
typedef std::function< bool(const FilePath &dir)> | RestoreCallback |
Callback type used to determine whether a backup should be restored or not. More... | |
Public Member Functions | |
TransactionalFileSystem ()=delete | |
TransactionalFileSystem (const FilePath &filepath, bool writable=false, RestoreCallback restoreCallback=RestoreCallback(), DirectoryLock::LockHandlerCallback lockCallback=nullptr, QObject *parent=nullptr) | |
TransactionalFileSystem (const TransactionalFileSystem &other)=delete | |
virtual | ~TransactionalFileSystem () noexcept |
const FilePath & | getPath () const noexcept |
bool | isWritable () const noexcept |
bool | isRestoredFromAutosave () const noexcept |
virtual FilePath | getAbsPath (const QString &path="") const noexcept override |
virtual QStringList | getDirs (const QString &path="") const noexcept override |
virtual QStringList | getFiles (const QString &path="") const noexcept override |
virtual bool | fileExists (const QString &path) const noexcept override |
virtual QByteArray | read (const QString &path) const override |
virtual QByteArray | readIfExists (const QString &path) const override |
virtual void | write (const QString &path, const QByteArray &content) override |
virtual void | renameFile (const QString &src, const QString &dst) override |
virtual void | removeFile (const QString &path) override |
virtual void | removeDirRecursively (const QString &path="") override |
void | loadFromZip (QByteArray content) |
void | loadFromZip (const FilePath &fp) |
QByteArray | exportToZip (FilterFunction filter=nullptr) const |
void | exportToZip (const FilePath &fp, FilterFunction filter=nullptr) const |
void | discardChanges () noexcept |
QStringList | checkForModifications () const |
void | autosave () |
void | save () |
void | releaseLock () |
Public Member Functions inherited from FileSystem | |
FileSystem (QObject *parent=nullptr) noexcept | |
virtual | ~FileSystem () noexcept |
virtual FilePath | getAbsPath (const QString &path="") const noexcept=0 |
virtual QStringList | getDirs (const QString &path="") const noexcept=0 |
virtual QStringList | getFiles (const QString &path="") const noexcept=0 |
virtual bool | fileExists (const QString &path) const noexcept=0 |
virtual QByteArray | read (const QString &path) const =0 |
virtual QByteArray | readIfExists (const QString &path) const =0 |
virtual void | write (const QString &path, const QByteArray &content)=0 |
virtual void | renameFile (const QString &src, const QString &dst)=0 |
virtual void | removeFile (const QString &path)=0 |
virtual void | removeDirRecursively (const QString &path="")=0 |
Static Public Member Functions | |
static std::shared_ptr< TransactionalFileSystem > | open (const FilePath &filepath, bool writable, RestoreCallback restoreCallback=&RestoreMode::no, DirectoryLock::LockHandlerCallback lockCallback=nullptr, QObject *parent=nullptr) |
static std::shared_ptr< TransactionalFileSystem > | openRO (const FilePath &filepath, RestoreCallback restoreCallback=&RestoreMode::no, QObject *parent=nullptr) |
static std::shared_ptr< TransactionalFileSystem > | openRW (const FilePath &filepath, RestoreCallback restoreCallback=&RestoreMode::no, DirectoryLock::LockHandlerCallback lockCallback=nullptr, QObject *parent=nullptr) |
static QString | cleanPath (QString path) noexcept |
Private Member Functions | |
bool | isRemoved (const QString &path) const noexcept |
void | exportDirToZip (QuaZipFile &file, const FilePath &zipFp, const QString &dir, FilterFunction filter) const |
void | saveDiff (const QString &type) const |
void | loadDiff (const FilePath &fp) |
void | removeDiff (const QString &type) |
Private Attributes | |
const FilePath | mFilePath |
bool | mIsWritable |
DirectoryLock | mLock |
bool | mRestoredFromAutosave |
QRecursiveMutex | mMutex |
QHash< QString, QByteArray > | mModifiedFiles |
QSet< QString > | mRemovedFiles |
QSet< QString > | mRemovedDirs |
Transactional librepcb::FileSystem implementation.
This is an implementation of the librepcb::FileSystem interface with many features needed to create, open and save LibrePCB library elements and projects in a very safe way to always guarantee consistency of all files.
It handles following things:
In addition, all public methods of this class are thread-safe, i.e. concurrent access to the file system from multiple threads is allowed. However, be careful anyway as thread-safety does not mean you cannot generate an inconsisntent content of the file system. Generally it's recommended to make write operations only from one thread, and only read operations from all other threads.
typedef std::function<bool(const QString& filePath)> FilterFunction |
Function to filter files.
filePath | The relative file path to filter. |
true | Include file. |
false | Do not include file. |
typedef std::function<bool(const FilePath& dir)> RestoreCallback |
Callback type used to determine whether a backup should be restored or not.
dir | The directory to be restored. |
true | Restore backup. |
false | Do not restore backup. |
librepcb::Exception | to abort opening the directory. |
|
delete |
TransactionalFileSystem | ( | const FilePath & | filepath, |
bool | writable = false , |
||
RestoreCallback | restoreCallback = RestoreCallback() , |
||
DirectoryLock::LockHandlerCallback | lockCallback = nullptr , |
||
QObject * | parent = nullptr |
||
) |
|
delete |
|
virtualnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
overridevirtualnoexcept |
Implements FileSystem.
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
void loadFromZip | ( | QByteArray | content | ) |
void loadFromZip | ( | const FilePath & | fp | ) |
QByteArray exportToZip | ( | FilterFunction | filter = nullptr | ) | const |
void exportToZip | ( | const FilePath & | fp, |
FilterFunction | filter = nullptr |
||
) | const |
|
noexcept |
QStringList checkForModifications | ( | ) | const |
void autosave | ( | ) |
void save | ( | ) |
void releaseLock | ( | ) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
staticnoexcept |
|
privatenoexcept |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |