From 079763f09ade2d6e92a5995c1c02fad42c8e48cd Mon Sep 17 00:00:00 2001 From: nielash Date: Fri, 6 Oct 2023 16:36:00 -0400 Subject: [PATCH] bisync: isDir check for deltas Before this change, if --create-empty-src-dirs was specified, bisync would include directories in the list of deltas to evaluate by their modtime, relative to the prior sync. This was unnecessary, as rclone does not yet support setting modtime for directories. After this change, we skip directories when comparing modtimes. (In other words, we care only if a directory is created or deleted, not whether it is newer or older.) --- cmd/bisync/deltas.go | 23 +++++++++++++---------- cmd/bisync/listing.go | 11 +++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/cmd/bisync/deltas.go b/cmd/bisync/deltas.go index 9d565eba6..87e274d0e 100644 --- a/cmd/bisync/deltas.go +++ b/cmd/bisync/deltas.go @@ -174,18 +174,21 @@ func (b *bisyncRun) findDeltas(fctx context.Context, f fs.Fs, oldListing, newLis ds.deleted++ d |= deltaDeleted } else { - if old.getTime(file) != now.getTime(file) { - if old.beforeOther(now, file) { - fs.Debugf(file, "(old: %v current: %v", old.getTime(file), now.getTime(file)) - b.indent(msg, file, "File is newer") - d |= deltaNewer - } else { // Current version is older than prior sync. - fs.Debugf(file, "(old: %v current: %v", old.getTime(file), now.getTime(file)) - b.indent(msg, file, "File is OLDER") - d |= deltaOlder + // skip dirs here, as we only care if they are new/deleted, not newer/older + if !now.isDir(file) { + if old.getTime(file) != now.getTime(file) { + if old.beforeOther(now, file) { + fs.Debugf(file, "(old: %v current: %v", old.getTime(file), now.getTime(file)) + b.indent(msg, file, "File is newer") + d |= deltaNewer + } else { // Current version is older than prior sync. + fs.Debugf(file, "(old: %v current: %v", old.getTime(file), now.getTime(file)) + b.indent(msg, file, "File is OLDER") + d |= deltaOlder + } } + // TODO Compare sizes and hashes } - // TODO Compare sizes and hashes } if d.is(deltaModified) { diff --git a/cmd/bisync/listing.go b/cmd/bisync/listing.go index 4a71d1500..a6474b78a 100644 --- a/cmd/bisync/listing.go +++ b/cmd/bisync/listing.go @@ -128,6 +128,17 @@ func (ls *fileList) getTime(file string) time.Time { return fi.time } +// also returns false if not found +func (ls *fileList) isDir(file string) bool { + fi := ls.get(file) + if fi != nil { + if fi.flags == "d" { + return true + } + } + return false +} + func (ls *fileList) beforeOther(other *fileList, file string) bool { thisTime := ls.getTime(file) thatTime := other.getTime(file)