qBittorrent
AsyncFileStorage Class Reference

#include <asyncfilestorage.h>

Inheritance diagram for AsyncFileStorage:
Collaboration diagram for AsyncFileStorage:

Signals

void failed (const QString &fileName, const QString &errorString)
 

Public Member Functions

 AsyncFileStorage (const QString &storageFolderPath, QObject *parent=nullptr)
 
 ~AsyncFileStorage () override
 
void store (const QString &fileName, const QByteArray &data)
 
QDir storageDir () const
 

Private Member Functions

Q_INVOKABLE void store_impl (const QString &fileName, const QByteArray &data)
 

Private Attributes

QDir m_storageDir
 
QFile m_lockFile
 

Detailed Description

Definition at line 43 of file asyncfilestorage.h.

Constructor & Destructor Documentation

◆ AsyncFileStorage()

AsyncFileStorage::AsyncFileStorage ( const QString &  storageFolderPath,
QObject *  parent = nullptr 
)
explicit

Definition at line 36 of file asyncfilestorage.cpp.

37  : QObject(parent)
38  , m_storageDir(storageFolderPath)
39  , m_lockFile(m_storageDir.absoluteFilePath(QStringLiteral("storage.lock")))
40 {
41  if (!m_storageDir.mkpath(m_storageDir.absolutePath()))
43  {tr("Could not create directory '%1'.")
44  .arg(m_storageDir.absolutePath())};
45 
46  // TODO: This folder locking approach does not work for UNIX systems. Implement it.
47  if (!m_lockFile.open(QFile::WriteOnly))
48  throw AsyncFileStorageError {m_lockFile.errorString()};
49 }

References m_lockFile, and m_storageDir.

◆ ~AsyncFileStorage()

AsyncFileStorage::~AsyncFileStorage ( )
override

Definition at line 51 of file asyncfilestorage.cpp.

52 {
53  m_lockFile.close();
54  m_lockFile.remove();
55 }

References m_lockFile.

Member Function Documentation

◆ failed

void AsyncFileStorage::failed ( const QString &  fileName,
const QString &  errorString 
)
signal

Referenced by RSS::AutoDownloader::AutoDownloader(), RSS::Session::Session(), and store_impl().

Here is the caller graph for this function:

◆ storageDir()

QDir AsyncFileStorage::storageDir ( ) const

Definition at line 63 of file asyncfilestorage.cpp.

64 {
65  return m_storageDir;
66 }

References m_storageDir.

Referenced by RSS::Feed::cleanup(), RSS::Feed::Feed(), RSS::AutoDownloader::load(), RSS::Feed::load(), and RSS::Session::load().

Here is the caller graph for this function:

◆ store()

void AsyncFileStorage::store ( const QString &  fileName,
const QByteArray &  data 
)

Definition at line 57 of file asyncfilestorage.cpp.

58 {
59  QMetaObject::invokeMethod(this, [this, data, fileName]() { store_impl(fileName, data); }
60  , Qt::QueuedConnection);
61 }
Q_INVOKABLE void store_impl(const QString &fileName, const QByteArray &data)
QString fileName(const QString &filePath)
Definition: fs.cpp:87

References Utils::Fs::fileName(), and store_impl().

Referenced by RSS::AutoDownloader::store(), RSS::Feed::store(), and RSS::Session::store().

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

◆ store_impl()

void AsyncFileStorage::store_impl ( const QString &  fileName,
const QByteArray &  data 
)
private

Definition at line 68 of file asyncfilestorage.cpp.

69 {
70  const QString filePath = m_storageDir.absoluteFilePath(fileName);
71  qDebug() << "AsyncFileStorage: Saving data to" << filePath;
72 
73  const nonstd::expected<void, QString> result = Utils::IO::saveToFile(filePath, data);
74  if (!result)
75  {
76  qDebug() << "AsyncFileStorage: Failed to save data";
77  emit failed(filePath, result.error());
78  }
79 }
void failed(const QString &fileName, const QString &errorString)
nonstd::expected< void, QString > saveToFile(const QString &path, const QByteArray &data)
Definition: io.cpp:69

References failed(), Utils::Fs::fileName(), m_storageDir, and Utils::IO::saveToFile().

Referenced by store().

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

Member Data Documentation

◆ m_lockFile

QFile AsyncFileStorage::m_lockFile
private

Definition at line 63 of file asyncfilestorage.h.

Referenced by AsyncFileStorage(), and ~AsyncFileStorage().

◆ m_storageDir

QDir AsyncFileStorage::m_storageDir
private

Definition at line 62 of file asyncfilestorage.h.

Referenced by AsyncFileStorage(), storageDir(), and store_impl().


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