From b61da487e44ace079f58c85ebf583ae4822c040c Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 10 Feb 2020 10:48:30 +0100 Subject: [PATCH] all: Update metadata modtime on delete (ref #6284) (#6315) This records the time a file was marked as deleted. It will, in the future, aid in garbage collecting old files. --- lib/db/structs.go | 13 +++++++++++++ lib/model/folder.go | 19 ++++--------------- lib/model/folder_recvonly.go | 3 +-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/db/structs.go b/lib/db/structs.go index ca786a1b8..c179eb963 100644 --- a/lib/db/structs.go +++ b/lib/db/structs.go @@ -127,6 +127,7 @@ func (f FileInfoTruncated) FilePermissions() uint32 { func (f FileInfoTruncated) FileModifiedBy() protocol.ShortID { return f.ModifiedBy } + func (f FileInfoTruncated) ConvertToIgnoredFileInfo(by protocol.ShortID) protocol.FileInfo { return protocol.FileInfo{ Name: f.Name, @@ -140,6 +141,18 @@ func (f FileInfoTruncated) ConvertToIgnoredFileInfo(by protocol.ShortID) protoco } } +func (f FileInfoTruncated) ConvertToDeletedFileInfo(by protocol.ShortID, localFlags uint32) protocol.FileInfo { + return protocol.FileInfo{ + Name: f.Name, + Type: f.Type, + ModifiedS: time.Now().Unix(), + ModifiedBy: by, + Deleted: true, + Version: f.Version.Update(by), + LocalFlags: localFlags, + } +} + func (c Counts) Add(other Counts) Counts { return Counts{ Files: c.Files + other.Files, diff --git a/lib/model/folder.go b/lib/model/folder.go index 3d8b0ef7e..9b6baf82a 100644 --- a/lib/model/folder.go +++ b/lib/model/folder.go @@ -532,22 +532,11 @@ func (f *folder) scanSubdirs(subDirs []string) error { } return true } - nf := protocol.FileInfo{ - Name: file.Name, - Type: file.Type, - Size: 0, - ModifiedS: file.ModifiedS, - ModifiedNs: file.ModifiedNs, - ModifiedBy: f.shortID, - Deleted: true, - Version: file.Version.Update(f.shortID), - LocalFlags: f.localFlags, - } - // We do not want to override the global version - // with the deleted file. Setting to an empty - // version makes sure the file gets in sync on - // the following pull. + nf := file.ConvertToDeletedFileInfo(f.shortID, f.localFlags) if file.ShouldConflict() { + // We do not want to override the global version with + // the deleted file. Setting to an empty version makes + // sure the file gets in sync on the following pull. nf.Version = protocol.Vector{} } diff --git a/lib/model/folder_recvonly.go b/lib/model/folder_recvonly.go index 2639afab2..02084211b 100644 --- a/lib/model/folder_recvonly.go +++ b/lib/model/folder_recvonly.go @@ -107,8 +107,7 @@ func (f *receiveOnlyFolder) Revert() { fi = protocol.FileInfo{ Name: fi.Name, Type: fi.Type, - ModifiedS: fi.ModifiedS, - ModifiedNs: fi.ModifiedNs, + ModifiedS: time.Now().Unix(), ModifiedBy: f.shortID, Deleted: true, Version: protocol.Vector{}, // if this file ever resurfaces anywhere we want our delete to be strictly older