![]() |
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 void | write (const QString &path, const QByteArray &content) 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 () |
![]() | |
FileSystem (QObject *parent=nullptr) noexcept | |
virtual | ~FileSystem () noexcept |
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 | |
FilePath | mFilePath |
bool | mIsWritable |
DirectoryLock | mLock |
bool | mRestoredFromAutosave |
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:
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 |
Implements FileSystem.
|
overridevirtualnoexcept |
Implements FileSystem.
|
overridevirtualnoexcept |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
|
overridevirtual |
Implements FileSystem.
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 | ( | ) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
staticnoexcept |
|
privatenoexcept |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |