LibrePCB Developers Documentation
TransactionalFileSystem Class Referencefinal

Transactional librepcb::FileSystem implementation. More...

#include <transactionalfilesystem.h>

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

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 FilePathgetPath () 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 ()
 
- Public Member Functions inherited from FileSystem
 FileSystem (QObject *parent=nullptr) noexcept
 
virtual ~FileSystem () noexcept
 

Static Public Member Functions

static std::shared_ptr< TransactionalFileSystemopen (const FilePath &filepath, bool writable, RestoreCallback restoreCallback=&RestoreMode::no, DirectoryLock::LockHandlerCallback lockCallback=nullptr, QObject *parent=nullptr)
 
static std::shared_ptr< TransactionalFileSystemopenRO (const FilePath &filepath, RestoreCallback restoreCallback=&RestoreMode::no, QObject *parent=nullptr)
 
static std::shared_ptr< TransactionalFileSystemopenRW (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
 

Detailed Description

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:

Member Typedef Documentation

◆ FilterFunction

typedef std::function<bool(const QString& filePath)> FilterFunction

Function to filter files.

Parameters
filePathThe relative file path to filter.
Return values
trueInclude file.
falseDo not include file.

◆ RestoreCallback

typedef std::function<bool(const FilePath& dir)> RestoreCallback

Callback type used to determine whether a backup should be restored or not.

Parameters
dirThe directory to be restored.
Return values
trueRestore backup.
falseDo not restore backup.
Exceptions
librepcb::Exceptionto abort opening the directory.

Constructor & Destructor Documentation

◆ TransactionalFileSystem() [1/3]

+ Here is the caller graph for this function:

◆ TransactionalFileSystem() [2/3]

TransactionalFileSystem ( const FilePath filepath,
bool  writable = false,
RestoreCallback  restoreCallback = RestoreCallback(),
DirectoryLock::LockHandlerCallback  lockCallback = nullptr,
QObject *  parent = nullptr 
)
+ Here is the call graph for this function:

◆ TransactionalFileSystem() [3/3]

◆ ~TransactionalFileSystem()

~TransactionalFileSystem ( )
virtualnoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ getPath()

const FilePath& getPath ( ) const
inlinenoexcept
+ Here is the caller graph for this function:

◆ isWritable()

bool isWritable ( ) const
inlinenoexcept

◆ isRestoredFromAutosave()

bool isRestoredFromAutosave ( ) const
inlinenoexcept
+ Here is the call graph for this function:

◆ getAbsPath()

FilePath getAbsPath ( const QString &  path = "") const
overridevirtualnoexcept

Implements FileSystem.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDirs()

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

Implements FileSystem.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFiles()

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

Implements FileSystem.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fileExists()

bool fileExists ( const QString &  path) const
overridevirtualnoexcept

Implements FileSystem.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

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:

◆ write()

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:

◆ removeFile()

void removeFile ( const QString &  path)
overridevirtual

Implements FileSystem.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeDirRecursively()

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

Implements FileSystem.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFromZip() [1/2]

void loadFromZip ( QByteArray  content)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFromZip() [2/2]

void loadFromZip ( const FilePath fp)
+ Here is the call graph for this function:

◆ exportToZip() [1/2]

QByteArray exportToZip ( FilterFunction  filter = nullptr) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exportToZip() [2/2]

void exportToZip ( const FilePath fp,
FilterFunction  filter = nullptr 
) const
+ Here is the call graph for this function:

◆ discardChanges()

void discardChanges ( )
noexcept
+ Here is the caller graph for this function:

◆ checkForModifications()

QStringList checkForModifications ( ) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ autosave()

void autosave ( )
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

void save ( )
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open()

static std::shared_ptr<TransactionalFileSystem> open ( const FilePath filepath,
bool  writable,
RestoreCallback  restoreCallback = &RestoreMode::no,
DirectoryLock::LockHandlerCallback  lockCallback = nullptr,
QObject *  parent = nullptr 
)
inlinestatic
+ Here is the caller graph for this function:

◆ openRO()

static std::shared_ptr<TransactionalFileSystem> openRO ( const FilePath filepath,
RestoreCallback  restoreCallback = &RestoreMode::no,
QObject *  parent = nullptr 
)
inlinestatic
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ openRW()

static std::shared_ptr<TransactionalFileSystem> openRW ( const FilePath filepath,
RestoreCallback  restoreCallback = &RestoreMode::no,
DirectoryLock::LockHandlerCallback  lockCallback = nullptr,
QObject *  parent = nullptr 
)
inlinestatic
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanPath()

QString cleanPath ( QString  path)
staticnoexcept
+ Here is the caller graph for this function:

◆ isRemoved()

bool isRemoved ( const QString &  path) const
privatenoexcept
+ Here is the caller graph for this function:

◆ exportDirToZip()

void exportDirToZip ( QuaZipFile &  file,
const FilePath zipFp,
const QString &  dir,
FilterFunction  filter 
) const
private
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveDiff()

void saveDiff ( const QString &  type) const
private
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadDiff()

void loadDiff ( const FilePath fp)
private
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeDiff()

void removeDiff ( const QString &  type)
private
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mFilePath

FilePath mFilePath
private

◆ mIsWritable

bool mIsWritable
private

◆ mLock

DirectoryLock mLock
private

◆ mRestoredFromAutosave

bool mRestoredFromAutosave
private

◆ mModifiedFiles

QHash<QString, QByteArray> mModifiedFiles
private

◆ mRemovedFiles

QSet<QString> mRemovedFiles
private

◆ mRemovedDirs

QSet<QString> mRemovedDirs
private

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