mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 19:40:18 -07:00
parent
facfa26eed
commit
dd1bd8ad10
131 changed files with 2252 additions and 1868 deletions
|
@ -31,21 +31,22 @@
|
|||
#include <QDebug>
|
||||
#include <QMetaObject>
|
||||
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/io.h"
|
||||
|
||||
AsyncFileStorage::AsyncFileStorage(const QString &storageFolderPath, QObject *parent)
|
||||
AsyncFileStorage::AsyncFileStorage(const Path &storageFolderPath, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_storageDir(storageFolderPath)
|
||||
, m_lockFile(m_storageDir.absoluteFilePath(QStringLiteral("storage.lock")))
|
||||
, m_lockFile((m_storageDir / Path(QStringLiteral("storage.lock"))).data())
|
||||
{
|
||||
if (!m_storageDir.mkpath(m_storageDir.absolutePath()))
|
||||
throw AsyncFileStorageError
|
||||
{tr("Could not create directory '%1'.")
|
||||
.arg(m_storageDir.absolutePath())};
|
||||
Q_ASSERT(m_storageDir.isAbsolute());
|
||||
|
||||
if (!Utils::Fs::mkpath(m_storageDir))
|
||||
throw AsyncFileStorageError(tr("Could not create directory '%1'.").arg(m_storageDir.toString()));
|
||||
|
||||
// TODO: This folder locking approach does not work for UNIX systems. Implement it.
|
||||
if (!m_lockFile.open(QFile::WriteOnly))
|
||||
throw AsyncFileStorageError {m_lockFile.errorString()};
|
||||
throw AsyncFileStorageError(m_lockFile.errorString());
|
||||
}
|
||||
|
||||
AsyncFileStorage::~AsyncFileStorage()
|
||||
|
@ -54,21 +55,21 @@ AsyncFileStorage::~AsyncFileStorage()
|
|||
m_lockFile.remove();
|
||||
}
|
||||
|
||||
void AsyncFileStorage::store(const QString &fileName, const QByteArray &data)
|
||||
void AsyncFileStorage::store(const Path &filePath, const QByteArray &data)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, data, fileName]() { store_impl(fileName, data); }
|
||||
QMetaObject::invokeMethod(this, [this, data, filePath]() { store_impl(filePath, data); }
|
||||
, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QDir AsyncFileStorage::storageDir() const
|
||||
Path AsyncFileStorage::storageDir() const
|
||||
{
|
||||
return m_storageDir;
|
||||
}
|
||||
|
||||
void AsyncFileStorage::store_impl(const QString &fileName, const QByteArray &data)
|
||||
void AsyncFileStorage::store_impl(const Path &fileName, const QByteArray &data)
|
||||
{
|
||||
const QString filePath = m_storageDir.absoluteFilePath(fileName);
|
||||
qDebug() << "AsyncFileStorage: Saving data to" << filePath;
|
||||
const Path filePath = m_storageDir / fileName;
|
||||
qDebug() << "AsyncFileStorage: Saving data to" << filePath.toString();
|
||||
|
||||
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(filePath, data);
|
||||
if (!result)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue