|
swift
|
A subclass of QFile which writes to a temporary file while it is open, then renames the file when it is closed, so that it overwrites the target file as a single, atomic transaction. More...
Public Member Functions | |
| CAtomicFile (const QString &filename) | |
| ~CAtomicFile () | |
| bool | open (OpenMode mode) |
| void | close () |
| bool | checkedClose () |
| Calls close() and returns false if there was an error at any stage. | |
| void | abandon () |
| Closes the file without renaming it. | |
| FileError | error () const |
| void | unsetError () |
Public Member Functions inherited from QFile | |
| QFile (QObject *parent) | |
| QFile (const QString &name) | |
| QFile (const QString &name, QObject *parent) | |
| QFile (const std::filesystem::path &name) | |
| QFile (const std::filesystem::path &name, QObject *parent) | |
| bool | copy (const QString &newName) |
| bool | copy (const std::filesystem::path &newName) |
| bool | link (const QString &linkName) |
| bool | link (const std::filesystem::path &newName) |
| bool | moveToTrash () |
| bool | open (FILE *fh, QIODeviceBase::OpenMode mode, QFileDevice::FileHandleFlags handleFlags) |
| virtual bool | open (QIODeviceBase::OpenMode mode) override |
| bool | open (QIODeviceBase::OpenMode mode, QFileDevice::Permissions permissions) |
| bool | open (int fd, QIODeviceBase::OpenMode mode, QFileDevice::FileHandleFlags handleFlags) |
| bool | remove () |
| bool | rename (const QString &newName) |
| bool | rename (const std::filesystem::path &newName) |
| virtual bool | resize (qint64 sz) override |
| virtual bool | setPermissions (QFileDevice::Permissions permissions) override |
| void | setFileName (const QString &name) |
| void | setFileName (const std::filesystem::path &name) |
| virtual QFileDevice::Permissions | permissions () const const override |
| virtual QString | fileName () const const override |
| QString | symLinkTarget () const const |
| bool | exists () const const |
| virtual qint64 | size () const const override |
| std::filesystem::path | filesystemFileName () const const |
| std::filesystem::path | filesystemSymLinkTarget () const const |
Public Member Functions inherited from QFileDevice | |
| QT_NO_USE_NODISCARD_FILE_OPEN QT_NO_USE_NODISCARD_FILE_OPEN | |
| QT_USE_NODISCARD_FILE_OPEN QT_USE_NODISCARD_FILE_OPEN | |
| bool | flush () |
| virtual bool | seek (qint64 pos) override |
| bool | setFileTime (const QDateTime &newDate, QFileDevice::FileTime fileTime) |
| bool | unmap (uchar *address) |
| uchar * | map (qint64 offset, qint64 size, QFileDevice::MemoryMapFlags flags) |
| void | unsetError () |
| QDateTime | fileTime (QFileDevice::FileTime time) const const |
| QFileDevice::FileError | error () const const |
| virtual bool | atEnd () const const override |
| virtual bool | isSequential () const const override |
| int | handle () const const |
| virtual qint64 | pos () const const override |
Public Member Functions inherited from QIODevice | |
| QByteArray | peek (qint64 maxSize) |
| QByteArray | read (qint64 maxSize) |
| QByteArray | readAll () |
| QByteArray | readLine (qint64 maxSize) |
| QByteArrayView | readLineInto (QSpan< char > buffer) |
| QByteArrayView | readLineInto (QSpan< std::byte > buffer) |
| QByteArrayView | readLineInto (QSpan< uchar > buffer) |
| QIODevice (QObject *parent) | |
| bool | getChar (char *c) |
| bool | putChar (char c) |
| bool | readLineInto (QByteArray *line, qint64 maxSize) |
| virtual bool | reset () |
| virtual bool | waitForBytesWritten (int msecs) |
| virtual bool | waitForReadyRead (int msecs) |
| qint64 | peek (char *data, qint64 maxSize) |
| qint64 | read (char *data, qint64 maxSize) |
| qint64 | readLine (char *data, qint64 maxSize) |
| qint64 | skip (qint64 maxSize) |
| qint64 | write (const QByteArray &data) |
| qint64 | write (const char *data) |
| qint64 | write (const char *data, qint64 maxSize) |
| void | aboutToClose () |
| void | bytesWritten (qint64 bytes) |
| void | channelBytesWritten (int channel, qint64 bytes) |
| void | channelReadyRead (int channel) |
| void | commitTransaction () |
| void | readChannelFinished () |
| void | readyRead () |
| void | rollbackTransaction () |
| void | setCurrentReadChannel (int channel) |
| void | setCurrentWriteChannel (int channel) |
| void | setTextModeEnabled (bool enabled) |
| void | startTransaction () |
| void | ungetChar (char c) |
| QIODeviceBase::OpenMode | openMode () const const |
| QString | errorString () const const |
| virtual bool | canReadLine () const const |
| bool | isOpen () const const |
| bool | isReadable () const const |
| bool | isTextModeEnabled () const const |
| bool | isTransactionStarted () const const |
| bool | isWritable () const const |
| int | currentReadChannel () const const |
| int | currentWriteChannel () const const |
| int | readChannelCount () const const |
| int | writeChannelCount () const const |
| virtual qint64 | bytesAvailable () const const |
| virtual qint64 | bytesToWrite () const const |
Public Member Functions inherited from QObject | |
| QBindable< QString > | bindableObjectName () |
| QObject (QObject *parent) | |
| QT_NO_CONTEXTLESS_CONNECT QT_NO_CONTEXTLESS_CONNECT | |
| QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT | |
| Q_CLASSINFO (Name, Value) | |
| Q_EMIT Q_EMIT | |
| Q_ENUM (...) | |
| Q_ENUMS (...) | |
| Q_ENUM_NS (...) | |
| Q_FLAG (...) | |
| Q_FLAGS (...) | |
| Q_FLAG_NS (...) | |
| Q_GADGET Q_GADGET | |
| Q_GADGET_EXPORT (EXPORT_MACRO) | |
| Q_INTERFACES (...) | |
| Q_INVOKABLE Q_INVOKABLE | |
| Q_MOC_INCLUDE Q_MOC_INCLUDE | |
| Q_NAMESPACE Q_NAMESPACE | |
| Q_NAMESPACE_EXPORT (EXPORT_MACRO) | |
| Q_OBJECT Q_OBJECT | |
| Q_PROPERTY (...) | |
| Q_REVISION Q_REVISION | |
| Q_SET_OBJECT_NAME (Object) | |
| Q_SIGNAL Q_SIGNAL | |
| Q_SIGNALS Q_SIGNALS | |
| Q_SLOT Q_SLOT | |
| Q_SLOTS Q_SLOTS | |
| T | qobject_cast (QObject *object) |
| T | qobject_cast (const QObject *object) |
| bool | blockSignals (bool block) |
| virtual bool | event (QEvent *e) |
| virtual bool | eventFilter (QObject *watched, QEvent *event) |
| bool | moveToThread (QThread *targetThread) |
| bool | setProperty (const char *name, QVariant &&value) |
| bool | setProperty (const char *name, const QVariant &value) |
| int | startTimer (int interval, Qt::TimerType timerType) |
| int | startTimer (std::chrono::nanoseconds interval, Qt::TimerType timerType) |
| void | deleteLater () |
| void | destroyed (QObject *obj) |
| void | installEventFilter (QObject *filterObj) |
| void | killTimer (Qt::TimerId id) |
| void | killTimer (int id) |
| void | objectNameChanged (const QString &objectName) |
| void | removeEventFilter (QObject *obj) |
| void | setObjectName (QAnyStringView name) |
| void | setObjectName (const QString &name) |
| void | setParent (QObject *parent) |
| QList< QByteArray > | dynamicPropertyNames () const const |
| QList< T > | findChildren (QAnyStringView name, Qt::FindChildOptions options) const const |
| QList< T > | findChildren (Qt::FindChildOptions options) const const |
| QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
| QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
| QObject * | parent () const const |
| QString | objectName () const const |
| QThread * | thread () const const |
| QVariant | property (const char *name) const const |
| T | findChild (QAnyStringView name, Qt::FindChildOptions options) const const |
| T | findChild (Qt::FindChildOptions options) const const |
| bool | disconnect (const QObject *receiver, const char *method) const const |
| bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
| bool | inherits (const char *className) const const |
| bool | isQuickItemType () const const |
| bool | isWidgetType () const const |
| bool | isWindowType () const const |
| bool | signalsBlocked () const const |
| virtual const QMetaObject * | metaObject () const const |
| const QObjectList & | children () const const |
| void | dumpObjectInfo () const const |
| void | dumpObjectTree () const const |
Additional Inherited Members | |
Public Types inherited from QFileDevice | |
| enum | FileError |
| enum | FileHandleFlag |
| enum | FileTime |
| enum | MemoryMapFlag |
| enum | Permission |
Public Types inherited from QObject | |
| enum | TimerId |
Public Types inherited from QIODeviceBase | |
| enum | OpenModeFlag |
Static Public Member Functions inherited from QFile | |
| QByteArray | encodeName (const QString &fileName) |
| QFileDevice::Permissions | permissions (const QString &fileName) |
| QFileDevice::Permissions | permissions (const std::filesystem::path &filename) |
| QString | decodeName (const QByteArray &localFileName) |
| QString | decodeName (const char *localFileName) |
| QString | symLinkTarget (const QString &fileName) |
| bool | copy (const QString &fileName, const QString &newName) |
| bool | exists (const QString &fileName) |
| bool | link (const QString &fileName, const QString &linkName) |
| bool | moveToTrash (const QString &fileName, QString *pathInTrash) |
| bool | remove (const QString &fileName) |
| bool | rename (const QString &oldName, const QString &newName) |
| bool | resize (const QString &fileName, qint64 sz) |
| bool | setPermissions (const QString &fileName, QFileDevice::Permissions permissions) |
| bool | setPermissions (const std::filesystem::path &filename, QFileDevice::Permissions permissionSpec) |
| bool | supportsMoveToTrash () |
| std::filesystem::path | filesystemSymLinkTarget (const std::filesystem::path &fileName) |
Static Public Member Functions inherited from QObject | |
| QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
| QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
| QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
| QString | tr (const char *sourceText, const char *disambiguation, int n) |
| bool | disconnect (const QMetaObject::Connection &connection) |
| bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
| bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
| bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
Public Attributes inherited from QFileDevice | |
| typedef | FileHandleFlags |
| typedef | MemoryMapFlags |
| typedef | Permissions |
| NoError | |
| ReadError | |
| WriteError | |
| FatalError | |
| ResourceError | |
| OpenError | |
| AbortError | |
| TimeOutError | |
| UnspecifiedError | |
| RemoveError | |
| RenameError | |
| PositionError | |
| ResizeError | |
| PermissionsError | |
| CopyError | |
| AutoCloseHandle | |
| DontCloseHandle | |
| FileAccessTime | |
| FileBirthTime | |
| FileMetadataChangeTime | |
| FileModificationTime | |
| NoOptions | |
| MapPrivateOption | |
| ReadOwner | |
| WriteOwner | |
| ExeOwner | |
| ReadUser | |
| WriteUser | |
| ExeUser | |
| ReadGroup | |
| WriteGroup | |
| ExeGroup | |
| ReadOther | |
| WriteOther | |
| ExeOther | |
Public Attributes inherited from QObject | |
| typedef | QObjectList |
| Invalid | |
Public Attributes inherited from QIODeviceBase | |
| typedef | OpenMode |
| NotOpen | |
| ReadOnly | |
| WriteOnly | |
| ReadWrite | |
| Append | |
| Truncate | |
| Text | |
| Unbuffered | |
| NewOnly | |
| ExistingOnly | |
Protected Member Functions inherited from QFileDevice | |
| virtual qint64 | readData (char *data, qint64 len) override |
| virtual qint64 | readLineData (char *data, qint64 maxlen) override |
| virtual qint64 | writeData (const char *data, qint64 len) override |
Protected Member Functions inherited from QIODevice | |
| virtual qint64 | skipData (qint64 maxSize) |
| void | setErrorString (const QString &str) |
| void | setOpenMode (QIODeviceBase::OpenMode openMode) |
Protected Member Functions inherited from QObject | |
| virtual void | childEvent (QChildEvent *event) |
| virtual void | connectNotify (const QMetaMethod &signal) |
| virtual void | customEvent (QEvent *event) |
| virtual void | disconnectNotify (const QMetaMethod &signal) |
| virtual void | timerEvent (QTimerEvent *event) |
| QObject * | sender () const const |
| bool | isSignalConnected (const QMetaMethod &signal) const const |
| int | receivers (const char *signal) const const |
| int | senderSignalIndex () const const |
Properties inherited from QObject | |
| objectName | |
A subclass of QFile which writes to a temporary file while it is open, then renames the file when it is closed, so that it overwrites the target file as a single, atomic transaction.
If the application crashes while data is still being written, the original file is unchanged.
Definition at line 25 of file atomicfile.h.
|
inline |
Definition at line 31 of file atomicfile.h.
| swift::misc::CAtomicFile::~CAtomicFile | ( | ) |
Definition at line 65 of file atomicfile.cpp.
|
virtual |
After closing the file, it is renamed so that it overwrites the target file.
Reimplemented from QFileDevice.
Definition at line 70 of file atomicfile.cpp.
| CAtomicFile::FileError swift::misc::CAtomicFile::error | ( | ) | const |
Definition at line 99 of file atomicfile.cpp.
| bool swift::misc::CAtomicFile::open | ( | OpenMode | mode | ) |
Just before opening the file, the filename is changed so we actually write to a temporary file.
Definition at line 41 of file atomicfile.cpp.
| void swift::misc::CAtomicFile::unsetError | ( | ) |
Definition at line 106 of file atomicfile.cpp.