From: Christian Kamm Date: Fri, 25 Jan 2019 10:11:28 +0000 (+0100) Subject: Vfs: Enable propagating attributes on download X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~306 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=597cc60f52e85174621af7fe3d4d5ce8de57e713;p=nextcloud-desktop.git Vfs: Enable propagating attributes on download --- diff --git a/src/common/vfs.h b/src/common/vfs.h index 35e7b86ac..179f0174d 100644 --- a/src/common/vfs.h +++ b/src/common/vfs.h @@ -146,8 +146,15 @@ public: * * Implementations must make sure that calling this function on a file that already * is a placeholder is acceptable. + * + * replacesFile can optionally contain a filesystem path to a placeholder that this + * new placeholder shall supersede, for rename-replace actions with new downloads, + * for example. */ - virtual void convertToPlaceholder(const QString &filename, const SyncFileItem &item) = 0; + virtual void convertToPlaceholder( + const QString &filename, + const SyncFileItem &item, + const QString &replacesFile = QString()) = 0; /// Determine whether the file at the given absolute path is a dehydrated placeholder. virtual bool isDehydratedPlaceholder(const QString &filePath) = 0; @@ -234,7 +241,7 @@ public: bool updateMetadata(const QString &, time_t, quint64, const QByteArray &, QString *) override { return true; } void createPlaceholder(const QString &, const SyncFileItem &) override {} - void convertToPlaceholder(const QString &, const SyncFileItem &) override {} + void convertToPlaceholder(const QString &, const SyncFileItem &, const QString &) override {} bool isDehydratedPlaceholder(const QString &) override { return false; } bool statTypeVirtualFile(csync_file_stat_t *, void *) override { return false; } diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index fe0cceac7..7ae067797 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -421,6 +421,7 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked() if (_item->_type == ItemTypeVirtualFileDehydration) { _item->_type = ItemTypeVirtualFile; // TODO: Could dehydrate without wiping the file entirely + // TODO: That would be useful as it could preserve file attributes (pins) auto fn = propagator()->getFilePath(_item->_file); qCDebug(lcPropagateDownload) << "dehydration: wiping base file" << fn; propagator()->_journal->deleteFileRecord(_item->_file); @@ -987,6 +988,9 @@ void PropagateDownloadFile::downloadFinished() // Apply the remote permissions FileSystem::setFileReadOnlyWeak(_tmpFile.fileName(), !_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite)); + // Make the file a hydrated placeholder if possible + propagator()->syncOptions()._vfs->convertToPlaceholder(_tmpFile.fileName(), *_item, fn); + QString error; emit propagator()->touchedFile(fn); // The fileChanged() check is done above to generate better error messages. @@ -1004,9 +1008,6 @@ void PropagateDownloadFile::downloadFinished() return; } - // Make the file a hydrated placeholder if possible - propagator()->syncOptions()._vfs->convertToPlaceholder(fn, *_item); - FileSystem::setFileHidden(fn, false); // Maybe we downloaded a newer version of the file than we thought we would... diff --git a/src/libsync/vfs/suffix/vfs_suffix.cpp b/src/libsync/vfs/suffix/vfs_suffix.cpp index 518decf70..711ee14ea 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.cpp +++ b/src/libsync/vfs/suffix/vfs_suffix.cpp @@ -70,7 +70,7 @@ void VfsSuffix::createPlaceholder(const QString &syncFolder, const SyncFileItem FileSystem::setModTime(fn, item._modtime); } -void VfsSuffix::convertToPlaceholder(const QString &, const SyncFileItem &) +void VfsSuffix::convertToPlaceholder(const QString &, const SyncFileItem &, const QString &) { // Nothing necessary } diff --git a/src/libsync/vfs/suffix/vfs_suffix.h b/src/libsync/vfs/suffix/vfs_suffix.h index 9c2a2cc08..97d444ffc 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.h +++ b/src/libsync/vfs/suffix/vfs_suffix.h @@ -40,7 +40,7 @@ public: bool updateMetadata(const QString &filePath, time_t modtime, quint64 size, const QByteArray &fileId, QString *error) override; void createPlaceholder(const QString &syncFolder, const SyncFileItem &item) override; - void convertToPlaceholder(const QString &filename, const SyncFileItem &item) override; + void convertToPlaceholder(const QString &filename, const SyncFileItem &item, const QString &) override; bool isDehydratedPlaceholder(const QString &filePath) override; bool statTypeVirtualFile(csync_file_stat_t *stat, void *stat_data) override;