LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TransactionalFileSystem Class Referencefinal

Special FileSystem implementation for libraries and projects. More...

#include <transactionalfilesystem.h>

+ Inheritance diagram for TransactionalFileSystem:
+ Collaboration diagram for TransactionalFileSystem:

Public Types

enum  RestoreMode
 

Public Member Functions

 TransactionalFileSystem ()=delete
 
 TransactionalFileSystem (const FilePath &filepath, bool writable=false, RestoreMode restoreMode=RestoreMode::NO, QObject *parent=nullptr)
 
 TransactionalFileSystem (const TransactionalFileSystem &other)=delete
 
virtual ~TransactionalFileSystem () noexcept
 
bool isWritable () const noexcept
 
bool isRestoredFromAutosave () const noexcept
 
virtual FilePath getAbsPath (const QString &path="") const noexceptoverride
 
virtual QStringList getDirs (const QString &path="") const noexceptoverride
 
virtual QStringList getFiles (const QString &path="") const noexceptoverride
 
virtual bool fileExists (const QString &path) const noexceptoverride
 
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 exportToZip (const FilePath &fp) const
 
void autosave ()
 
void save ()
 
- Public Member Functions inherited from FileSystem
 FileSystem (QObject *parent=nullptr) noexcept
 
virtual ~FileSystem () noexcept
 

Static Public Member Functions

static std::shared_ptr
< TransactionalFileSystem
open (const FilePath &filepath, bool writable, RestoreMode restoreMode=RestoreMode::NO, QObject *parent=nullptr)
 
static std::shared_ptr
< TransactionalFileSystem
openRO (const FilePath &filepath, RestoreMode restoreMode=RestoreMode::NO, QObject *parent=nullptr)
 
static std::shared_ptr
< TransactionalFileSystem
openRW (const FilePath &filepath, RestoreMode restoreMode=RestoreMode::NO, 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) const
 
void saveDiff (const QString &type) const
 
void loadDiff (const FilePath &fp)
 
void removeDiff (const QString &type)
 
void discardChanges () noexcept
 

Private Attributes

FilePath mFilePath
 
bool mIsWritable
 
DirectoryLock mLock
 
bool mRestoredFromAutosave
 
QHash< QString, QByteArray > mModifiedFiles
 
QSet< QString > mRemovedFiles
 
QSet< QString > mRemovedDirs
 

Detailed Description

Special FileSystem implementation for libraries and projects.

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:

Member Enumeration Documentation

enum RestoreMode
strong
Enumerator
NO 

Do not restore the backup.

YES 

Restore backup if available.

ASK 

Ask (with QMessageBox) whether to restore or not.

ABORT 

Throw a RuntimeError if a backup exists.

Constructor & Destructor Documentation

TransactionalFileSystem ( const FilePath filepath,
bool  writable = false,
RestoreMode  restoreMode = RestoreMode::NO,
QObject *  parent = nullptr 
)

+ Here is the call graph for this function:

~TransactionalFileSystem ( )
virtualnoexcept

+ Here is the call graph for this function:

Member Function Documentation

bool isWritable ( ) const
inlinenoexcept
bool isRestoredFromAutosave ( ) const
inlinenoexcept
FilePath getAbsPath ( const QString &  path = "") const
overridevirtualnoexcept

Implements FileSystem.

+ Here is the call graph for this function:

QStringList getDirs ( const QString &  path = "") const
overridevirtualnoexcept

Implements FileSystem.

+ Here is the caller graph for this function:

QStringList getFiles ( const QString &  path = "") const
overridevirtualnoexcept

Implements FileSystem.

+ Here is the caller graph for this function:

bool fileExists ( const QString &  path) const
overridevirtualnoexcept

Implements FileSystem.

QByteArray read ( const QString &  path) const
overridevirtual

Implements FileSystem.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void write ( const QString &  path,
const QByteArray &  content 
)
overridevirtual

Implements FileSystem.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void removeFile ( const QString &  path)
overridevirtual

Implements FileSystem.

+ Here is the call graph for this function:

void removeDirRecursively ( const QString &  path = "")
overridevirtual

Implements FileSystem.

+ Here is the call graph for this function:

void exportToZip ( const FilePath fp) const

+ Here is the call graph for this function:

void autosave ( )

+ Here is the call graph for this function:

void save ( )

+ Here is the call graph for this function:

static std::shared_ptr<TransactionalFileSystem> open ( const FilePath filepath,
bool  writable,
RestoreMode  restoreMode = RestoreMode::NO,
QObject *  parent = nullptr 
)
inlinestatic

+ Here is the caller graph for this function:

static std::shared_ptr<TransactionalFileSystem> openRO ( const FilePath filepath,
RestoreMode  restoreMode = RestoreMode::NO,
QObject *  parent = nullptr 
)
inlinestatic

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static std::shared_ptr<TransactionalFileSystem> openRW ( const FilePath filepath,
RestoreMode  restoreMode = RestoreMode::NO,
QObject *  parent = nullptr 
)
inlinestatic

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QString cleanPath ( QString  path)
staticnoexcept

+ Here is the caller graph for this function:

bool isRemoved ( const QString &  path) const
privatenoexcept

+ Here is the caller graph for this function:

void exportDirToZip ( QuaZipFile &  file,
const FilePath zipFp,
const QString &  dir 
) const
private

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void saveDiff ( const QString &  type) const
private

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void loadDiff ( const FilePath fp)
private

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void removeDiff ( const QString &  type)
private

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void discardChanges ( )
privatenoexcept

+ Here is the caller graph for this function:

Member Data Documentation

FilePath mFilePath
private
bool mIsWritable
private
DirectoryLock mLock
private
bool mRestoredFromAutosave
private
QHash<QString, QByteArray> mModifiedFiles
private
QSet<QString> mRemovedFiles
private
QSet<QString> mRemovedDirs
private

The documentation for this class was generated from the following files: