Skip to content

Commit

Permalink
if a virtual file change but bothing changed: set it as in sync
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Apr 12, 2024
1 parent d6ed678 commit 34bd559
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/common/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ class OCSYNC_EXPORT Vfs : public QObject
* If the remote metadata changes, the local placeholder's metadata should possibly
* change as well.
*/
Q_REQUIRED_RESULT virtual Result<void, QString> updateMetadata(const QString &filePath, time_t modtime, qint64 size, const QByteArray &fileId) = 0;
[[nodiscard]] virtual Result<void, QString> updateMetadata(const QString &filePath, time_t modtime, qint64 size, const QByteArray &fileId) = 0;

[[nodiscard]] virtual Result<Vfs::ConvertToPlaceholderResult, QString> updatePlaceholderMarkInSync(const QString &filePath, const QByteArray &fileId) = 0;

[[nodiscard]] virtual bool isPlaceHolderInSync(const QString &filePath) const = 0;

/// Create a new dehydrated placeholder. Called from PropagateDownload.
Q_REQUIRED_RESULT virtual Result<void, QString> createPlaceholder(const SyncFileItem &item) = 0;
Expand Down Expand Up @@ -325,6 +329,8 @@ class OCSYNC_EXPORT VfsOff : public Vfs
[[nodiscard]] bool isHydrating() const override { return false; }

Result<void, QString> updateMetadata(const QString &, time_t, qint64, const QByteArray &) override { return {}; }
Result<Vfs::ConvertToPlaceholderResult, QString> updatePlaceholderMarkInSync(const QString &filePath, const QByteArray &fileId) override {return {QString{}};}
bool isPlaceHolderInSync(const QString &filePath) const override { Q_UNUSED(filePath) return true; }
Result<void, QString> createPlaceholder(const SyncFileItem &) override { return {}; }
Result<void, QString> dehydratePlaceholder(const SyncFileItem &) override { return {}; }
Result<ConvertToPlaceholderResult, QString> convertToPlaceholder(const QString &, const SyncFileItem &, const QString &, const UpdateMetadataTypes) override { return ConvertToPlaceholderResult::Ok; }
Expand Down
22 changes: 19 additions & 3 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,27 @@ void Folder::slotWatchedPathChanged(const QString &path, ChangeReason reason)
&& !FileSystem::fileChanged(path, record._fileSize, record._modtime) && _vfs) {
spurious = true;

if (auto pinState = _vfs->pinState(relativePath.toString())) {
if (*pinState == PinState::AlwaysLocal && record.isVirtualFile())
const auto fileAvailability = _vfs->availability(relativePath.toString(), Vfs::AvailabilityRecursivity::NotRecursiveAvailability);

qCInfo(lcFolder) << path
<< "file size:" << record._fileSize << FileSystem::getSize(path)
<< "file modtime:" << record._modtime << FileSystem::getModTime(path)
<< "pin state:" << (*_vfs->pinState(relativePath.toString()))
<< "virtual file:" << (fileAvailability && *fileAvailability == VfsItemAvailability::OnlineOnly ? "is virtual file" : "is plain old file");

if (const auto pinState = _vfs->pinState(relativePath.toString())) {
if (*pinState == PinState::AlwaysLocal && fileAvailability && *fileAvailability == VfsItemAvailability::OnlineOnly) {
spurious = false;
}
if (*pinState == PinState::OnlineOnly && (!fileAvailability || *fileAvailability != VfsItemAvailability::OnlineOnly)) {
spurious = false;
if (*pinState == PinState::OnlineOnly && record.isFile())
}
if (*pinState == PinState::OnlineOnly && fileAvailability && *fileAvailability == VfsItemAvailability::OnlineOnly) {
qCInfo(lcFolder) << "Not a spurious notification for file" << relativePath;
const auto result = _vfs->updateMetadata(path, FileSystem::getModTime(path), FileSystem::getSize(path), record._fileId);
Q_UNUSED(result)
spurious = false;
}
} else {
spurious = false;
}
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/vfs/cfapi/vfs_cfapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ Result<void, QString> VfsCfApi::updateMetadata(const QString &filePath, time_t m
}
}

Result<Vfs::ConvertToPlaceholderResult, QString> VfsCfApi::updatePlaceholderMarkInSync(const QString &filePath, const QByteArray &fileId)
{
return cfapi::updatePlaceholderMarkInSync(filePath, fileId, {});
}

Result<void, QString> VfsCfApi::createPlaceholder(const SyncFileItem &item)
{
Q_ASSERT(params().filesystemPath.endsWith('/'));
Expand Down
4 changes: 4 additions & 0 deletions src/libsync/vfs/cfapi/vfs_cfapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class VfsCfApi : public Vfs

Result<void, QString> updateMetadata(const QString &filePath, time_t modtime, qint64 size, const QByteArray &fileId) override;

Result<Vfs::ConvertToPlaceholderResult, QString> updatePlaceholderMarkInSync(const QString &filePath, const QByteArray &fileId) override;

bool isPlaceHolderInSync(const QString &filePath) const override;

Result<void, QString> createPlaceholder(const SyncFileItem &item) override;
Result<void, QString> dehydratePlaceholder(const SyncFileItem &item) override;
Result<Vfs::ConvertToPlaceholderResult, QString> convertToPlaceholder(const QString &filename, const SyncFileItem &item, const QString &replacesFile, UpdateMetadataTypes updateType) override;
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/vfs/suffix/vfs_suffix.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class VfsSuffix : public Vfs
[[nodiscard]] bool isHydrating() const override;

Result<void, QString> updateMetadata(const QString &filePath, time_t modtime, qint64 size, const QByteArray &fileId) override;
Result<Vfs::ConvertToPlaceholderResult, QString> updatePlaceholderMarkInSync(const QString &filePath, const QByteArray &fileId) override {return {QString{}};}
bool isPlaceHolderInSync(const QString &filePath) const override { Q_UNUSED(filePath) return true; }

Result<void, QString> createPlaceholder(const SyncFileItem &item) override;
Result<void, QString> dehydratePlaceholder(const SyncFileItem &item) override;
Expand Down

0 comments on commit 34bd559

Please sign in to comment.