swift
Public Member Functions | List of all members
swift::misc::CAtomicFile Class Reference

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...

Inheritance diagram for swift::misc::CAtomicFile:
[legend]

Public Member Functions

 CAtomicFile (const QString &filename)
 
virtual ~CAtomicFile ()
 
virtual bool open (OpenMode mode)
 
virtual 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 ()
 

Detailed Description

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.

Fixme:
Consider using QSaveFile.

Definition at line 25 of file atomicfile.h.

Constructor & Destructor Documentation

◆ CAtomicFile()

swift::misc::CAtomicFile::CAtomicFile ( const QString &  filename)
inline

Definition at line 31 of file atomicfile.h.

◆ ~CAtomicFile()

swift::misc::CAtomicFile::~CAtomicFile ( )
virtual

Definition at line 68 of file atomicfile.cpp.

Member Function Documentation

◆ close()

void swift::misc::CAtomicFile::close ( )
virtual

After closing the file, it is renamed so that it overwrites the target file.

Definition at line 73 of file atomicfile.cpp.

◆ error()

CAtomicFile::FileError swift::misc::CAtomicFile::error ( ) const

Definition at line 102 of file atomicfile.cpp.

◆ open()

bool swift::misc::CAtomicFile::open ( OpenMode  mode)
virtual

Just before opening the file, the filename is changed so we actually write to a temporary file.

Definition at line 44 of file atomicfile.cpp.

◆ unsetError()

void swift::misc::CAtomicFile::unsetError ( )

Definition at line 109 of file atomicfile.cpp.


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