swift
atomicfile.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_ATOMICFILE_H
7 #define SWIFT_MISC_ATOMICFILE_H
8 
9 #include <QFile>
10 #include <QFileDevice>
11 #include <QString>
12 
13 #include "misc/swiftmiscexport.h"
14 
15 namespace swift::misc
16 {
25  class SWIFT_MISC_EXPORT CAtomicFile : public QFile
26  {
27  Q_OBJECT
28 
29  public:
31  CAtomicFile(const QString &filename) : QFile(filename) {}
32 
34  virtual ~CAtomicFile() override;
35 
38  virtual bool open(OpenMode mode) override;
39 
42  virtual void close() override;
43 
45  bool checkedClose();
46 
48  void abandon();
49 
51  FileError error() const;
52 
54  void unsetError();
55 
56  private:
57  static QString randomSuffix();
58  void replaceOriginal();
59 
60  QString m_originalFilename;
61  bool m_renameError = false;
62  bool m_permissionError = false;
63  };
64 } // namespace swift::misc
65 
66 #endif // SWIFT_MISC_ATOMICFILE_H
A subclass of QFile which writes to a temporary file while it is open, then renames the file when it ...
Definition: atomicfile.h:26
CAtomicFile(const QString &filename)
Definition: atomicfile.h:31
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.