class SyncJournalDb;
class VfsPrivate;
class SyncFileItem;
-typedef QSharedPointer<SyncFileItem> SyncFileItemPtr;
/** Collection of parameters for initializing a Vfs instance. */
struct OCSYNC_EXPORT VfsSetupParams
virtual bool updateMetadata(const QString &filePath, time_t modtime, quint64 size, const QByteArray &fileId, QString *error) = 0;
/// Create a new dehydrated placeholder. Called from PropagateDownload.
- virtual void createPlaceholder(const QString &syncFolder, const SyncFileItemPtr &item) = 0;
+ virtual void createPlaceholder(const QString &syncFolder, const SyncFileItem &item) = 0;
/** Convert a new file to a hydrated placeholder.
*
* Some VFS integrations expect that every file, including those that have all
* the remote data, are "placeholders". This function is called by PropagateDownload
* to convert newly downloaded, fully hydrated files into placeholders.
+ *
+ * Implementations must make sure that calling this function on a file that already
+ * is a placeholder is acceptable.
*/
- virtual void convertToPlaceholder(const QString &filename, const SyncFileItemPtr &item) = 0;
+ virtual void convertToPlaceholder(const QString &filename, const SyncFileItem &item) = 0;
/// Determine whether the file at the given absolute path is a dehydrated placeholder.
virtual bool isDehydratedPlaceholder(const QString &filePath) = 0;
bool isHydrating() const override { return false; }
bool updateMetadata(const QString &, time_t, quint64, const QByteArray &, QString *) override { return true; }
- void createPlaceholder(const QString &, const SyncFileItemPtr &) override {}
- void convertToPlaceholder(const QString &, const SyncFileItemPtr &) override {}
+ void createPlaceholder(const QString &, const SyncFileItem &) override {}
+ void convertToPlaceholder(const QString &, const SyncFileItem &) override {}
bool isDehydratedPlaceholder(const QString &) override { return false; }
bool statTypeVirtualFile(csync_file_stat_t *, void *) override { return false; }
return OCC::adjustRenamedPath(_renamedDirectories, original);
}
-bool OwncloudPropagator::updateMetadata(const SyncFileItem &item)
+bool OwncloudPropagator::updateMetadata(const SyncFileItem &item, const QString &localFolderPath, SyncJournalDb &journal, Vfs &vfs)
{
- QString fsPath = getFilePath(item.destination());
+ QString fsPath = localFolderPath + item.destination();
+ vfs.convertToPlaceholder(fsPath, item);
auto record = item.toSyncJournalFileRecordWithInode(fsPath);
- return _journal->setFileRecord(record);
+ return journal.setFileRecord(record);
+}
+
+bool OwncloudPropagator::updateMetadata(const SyncFileItem &item)
+{
+ return updateMetadata(item, _localDir, *_journal, *syncOptions()._vfs);
}
// ================================================================================
} else if (job->_item->_status != SyncFileItem::Success) {
qCWarning(lcCleanupPolls) << "There was an error with file " << job->_item->_file << job->_item->_errorString;
} else {
- // want to do Propagator::updateMetadata()
- QString filesystemPath = _localPath + job->_item->_file;
- if (!_journal->setFileRecord(job->_item->toSyncJournalFileRecordWithInode(filesystemPath))) {
+ if (!OwncloudPropagator::updateMetadata(*job->_item, _localPath, *_journal, *_vfs)) {
qCWarning(lcCleanupPolls) << "database error";
job->_item->_status = SyncFileItem::FatalError;
job->_item->_errorString = tr("Error writing metadata to the database");
*
* Typically after a sync operation succeeded. Updates the inode from
* the filesystem.
+ *
+ * Will also trigger a Vfs::convertToPlaceholder.
*/
- bool updateMetadata(const SyncFileItem &item);
+ static bool updateMetadata(const SyncFileItem &item, const QString &localFolderPath, SyncJournalDb &journal, Vfs &vfs);
+ bool updateMetadata(const SyncFileItem &item); // convenience for the above
private slots:
AccountPtr _account;
SyncJournalDb *_journal;
QString _localPath;
+ QSharedPointer<Vfs> _vfs;
public:
explicit CleanupPollsJob(const QVector<SyncJournalDb::PollInfo> &pollInfos, AccountPtr account,
- SyncJournalDb *journal, const QString &localPath, QObject *parent = nullptr)
+ SyncJournalDb *journal, const QString &localPath, const QSharedPointer<Vfs> &vfs, QObject *parent = nullptr)
: QObject(parent)
, _pollInfos(pollInfos)
, _account(account)
, _journal(journal)
, _localPath(localPath)
+ , _vfs(vfs)
{
}
auto fn = propagator()->getFilePath(_item->_file);
qCDebug(lcPropagateDownload) << "creating virtual file" << fn;
- vfs->createPlaceholder(propagator()->_localDir, _item);
+ vfs->createPlaceholder(propagator()->_localDir, *_item);
updateMetadata(false);
return;
}
}
// Make the file a hydrated placeholder if possible
- propagator()->syncOptions()._vfs->convertToPlaceholder(fn, _item);
+ propagator()->syncOptions()._vfs->convertToPlaceholder(fn, *_item);
FileSystem::setFileHidden(fn, false);
if (!pollInfos.isEmpty()) {
qCInfo(lcEngine) << "Finish Poll jobs before starting a sync";
auto *job = new CleanupPollsJob(pollInfos, _account,
- _journal, _localPath, this);
+ _journal, _localPath, _syncOptions._vfs, this);
connect(job, &CleanupPollsJob::finished, this, &SyncEngine::startSync);
connect(job, &CleanupPollsJob::aborted, this, &SyncEngine::slotCleanPollsJobAborted);
job->start();
return true;
}
-void VfsSuffix::createPlaceholder(const QString &syncFolder, const SyncFileItemPtr &item)
+void VfsSuffix::createPlaceholder(const QString &syncFolder, const SyncFileItem &item)
{
// The concrete shape of the placeholder is also used in isDehydratedPlaceholder() below
- QString fn = syncFolder + item->_file;
+ QString fn = syncFolder + item._file;
QFile file(fn);
file.open(QFile::ReadWrite | QFile::Truncate);
file.write(" ");
file.close();
- FileSystem::setModTime(fn, item->_modtime);
+ FileSystem::setModTime(fn, item._modtime);
}
-void VfsSuffix::convertToPlaceholder(const QString &, const SyncFileItemPtr &)
+void VfsSuffix::convertToPlaceholder(const QString &, const SyncFileItem &)
{
// Nothing necessary
}
bool updateMetadata(const QString &filePath, time_t modtime, quint64 size, const QByteArray &fileId, QString *error) override;
- void createPlaceholder(const QString &syncFolder, const SyncFileItemPtr &item) override;
- void convertToPlaceholder(const QString &filename, const SyncFileItemPtr &item) override;
+ void createPlaceholder(const QString &syncFolder, const SyncFileItem &item) override;
+ void convertToPlaceholder(const QString &filename, const SyncFileItem &item) override;
bool isDehydratedPlaceholder(const QString &filePath) override;
bool statTypeVirtualFile(csync_file_stat_t *stat, void *stat_data) override;