From b7e25e3f26785c3e3667471539234e5d4bafef9f Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Mon, 6 Dec 2021 14:43:55 +0100 Subject: Move dehydration into updateMetadata --- src/common/vfs.h | 8 ----- src/libsync/owncloudpropagator.cpp | 12 ++++++++ src/libsync/propagatedownload.cpp | 6 ---- src/libsync/vfs/suffix/vfs_suffix.cpp | 57 ++++++++++++++++------------------- src/libsync/vfs/suffix/vfs_suffix.h | 1 - 5 files changed, 38 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/common/vfs.h b/src/common/vfs.h index d2c768e8f..983c99910 100644 --- a/src/common/vfs.h +++ b/src/common/vfs.h @@ -164,13 +164,6 @@ public: /// Create a new dehydrated placeholder. Called from PropagateDownload. virtual OC_REQUIRED_RESULT Result createPlaceholder(const SyncFileItem &item) = 0; - /** Convert a hydrated placeholder to a dehydrated one. Called from PropagateDownlaod. - * - * This is different from delete+create because preserving some file metadata - * (like pin states) may be essential for some vfs plugins. - */ - virtual OC_REQUIRED_RESULT Result dehydratePlaceholder(const SyncFileItem &item) = 0; - /** Discovery hook: even unchanged files may need UPDATE_METADATA. * * For instance cfapi vfs wants local hydrated non-placeholder files to @@ -291,7 +284,6 @@ public: bool isHydrating() const override { return false; } Result createPlaceholder(const SyncFileItem &) override { return {}; } - Result dehydratePlaceholder(const SyncFileItem &) override { return {}; } bool needsMetadataUpdate(const SyncFileItem &) override { return false; } bool isDehydratedPlaceholder(const QString &) override { return false; } diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index a7e3dc005..6f0874d8a 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -756,6 +756,18 @@ QString OwncloudPropagator::adjustRenamedPath(const QString &original) const Result OwncloudPropagator::updatePlaceholder(const SyncFileItem &item, const QString &fileName, const QString &replacesFile) { + Q_ASSERT([&] { + if (item._type == ItemTypeVirtualFileDehydration) { + // when dehydrating the file must not be pinned + // don't use destinatio() with suffix placeholder + const auto pin = syncOptions()._vfs->pinState(item._file); + if (pin && pin.get() == PinState::AlwaysLocal) { + qDebug() << fileName << item.destination() << item._file; + return false; + } + } + return true; + }()); return syncOptions()._vfs->updateMetadata(item, fileName, replacesFile); } diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index b91a2e35a..7f491eecd 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -370,12 +370,6 @@ void PropagateDownloadFile::start() return; } qCDebug(lcPropagateDownload) << "dehydrating file" << _item->_file; - auto r = vfs->dehydratePlaceholder(*_item); - if (!r) { - done(SyncFileItem::NormalError, r.error()); - return; - } - propagator()->_journal->deleteFileRecord(_item->_originalFile); updateMetadata(false); return; } diff --git a/src/libsync/vfs/suffix/vfs_suffix.cpp b/src/libsync/vfs/suffix/vfs_suffix.cpp index 1641c8383..223655d14 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.cpp +++ b/src/libsync/vfs/suffix/vfs_suffix.cpp @@ -72,7 +72,28 @@ bool VfsSuffix::isHydrating() const Result VfsSuffix::updateMetadata(const SyncFileItem &item, const QString &filePath, const QString &) { - FileSystem::setModTime(filePath, item._modtime); + if (item._type == ItemTypeVirtualFileDehydration) { + SyncFileItem virtualItem(item); + virtualItem._file = item._renameTarget; + auto r = createPlaceholder(virtualItem); + if (!r) { + return r.error(); + } + // Move the item's pin state + auto pin = _setupParams.journal->internalPinStates().rawForPath(item._file.toUtf8()); + if (pin && *pin != PinState::Inherited) { + setPinState(item._renameTarget, *pin); + } + if (item._file != item._renameTarget) { // can be the same when renaming foo -> foo.owncloud to dehydrate + QString error; + if (!FileSystem::remove(_setupParams.filesystemPath + item._file, &error)) { + return error; + } + } + _setupParams.journal->deleteFileRecord(item._originalFile); + } else { + OC_ASSERT(FileSystem::setModTime(filePath, item._modtime)); + } return Vfs::ConvertToPlaceholderResult::Ok; } @@ -85,41 +106,15 @@ Result VfsSuffix::createPlaceholder(const SyncFileItem &item) QFile file(fn); if (file.exists() && file.size() > 1 && !FileSystem::verifyFileUnchanged(fn, item._size, item._modtime)) { - return QStringLiteral("Cannot create a placeholder because a file with the placeholder name already exist"); + return tr("Cannot create a placeholder because a file with the placeholder name already exist"); } - if (!file.open(QFile::ReadWrite | QFile::Truncate)) + if (!file.open(QFile::ReadWrite | QFile::Truncate)) { return file.errorString(); - + } file.write(" "); file.close(); - FileSystem::setModTime(fn, item._modtime); - return {}; -} - -Result VfsSuffix::dehydratePlaceholder(const SyncFileItem &item) -{ - SyncFileItem virtualItem(item); - virtualItem._file = item._renameTarget; - auto r = createPlaceholder(virtualItem); - if (!r) - return r; - - if (item._file != item._renameTarget) { // can be the same when renaming foo -> foo.owncloud to dehydrate - QFile::remove(_setupParams.filesystemPath + item._file); - } - - // Move the item's pin state - auto pin = _setupParams.journal->internalPinStates().rawForPath(item._file.toUtf8()); - if (pin && *pin != PinState::Inherited) { - setPinState(item._renameTarget, *pin); - setPinState(item._file, PinState::Inherited); - } - - // Ensure the pin state isn't contradictory - pin = pinState(item._renameTarget); - if (pin && *pin == PinState::AlwaysLocal) - setPinState(item._renameTarget, PinState::Unspecified); + OC_ASSERT(FileSystem::setModTime(fn, item._modtime)); return {}; } diff --git a/src/libsync/vfs/suffix/vfs_suffix.h b/src/libsync/vfs/suffix/vfs_suffix.h index f73a964b5..4899fc82f 100644 --- a/src/libsync/vfs/suffix/vfs_suffix.h +++ b/src/libsync/vfs/suffix/vfs_suffix.h @@ -42,7 +42,6 @@ public: Result createPlaceholder(const SyncFileItem &item) override; - Result dehydratePlaceholder(const SyncFileItem &item) override; bool needsMetadataUpdate(const SyncFileItem &) override { return false; } bool isDehydratedPlaceholder(const QString &filePath) override; -- cgit v1.2.3