From 4cc297ba4e81e5c19fa90fa1e6a2dca0d0be5c2e Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Fri, 22 May 2020 07:50:29 +0100 Subject: [PATCH] diff: Disable comparing modtimes when multimaster context is not found (#3226) --- cmd/diff-main.go | 5 ++++- cmd/difference.go | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/diff-main.go b/cmd/diff-main.go index f75c1b62..7e6e39c2 100644 --- a/cmd/diff-main.go +++ b/cmd/diff-main.go @@ -90,6 +90,8 @@ func (d diffMessage) String() string { msg = console.Colorize("DiffSize", "! "+d.SecondURL) case differInMetadata: msg = console.Colorize("DiffMetadata", "! "+d.SecondURL) + case differInMMSourceMTime: + msg = console.Colorize("DiffMMSourceMTime", "! "+d.SecondURL) default: fatalIf(errDummy().Trace(d.FirstURL, d.SecondURL), "Unhandled difference between `"+d.FirstURL+"` and `"+d.SecondURL+"`.") @@ -201,7 +203,8 @@ func mainDiff(ctx *cli.Context) error { console.SetColor("DiffOnlyInSecond", color.New(color.FgGreen)) console.SetColor("DiffType", color.New(color.FgMagenta)) console.SetColor("DiffSize", color.New(color.FgYellow, color.Bold)) - console.SetColor("DiffTime", color.New(color.FgYellow, color.Bold)) + console.SetColor("DiffMetadata", color.New(color.FgYellow, color.Bold)) + console.SetColor("DiffMMSourceMTime", color.New(color.FgYellow, color.Bold)) URLs := ctx.Args() firstURL := URLs.Get(0) diff --git a/cmd/difference.go b/cmd/difference.go index f68f91c9..7da4deb2 100644 --- a/cmd/difference.go +++ b/cmd/difference.go @@ -34,11 +34,11 @@ type differType int const ( differInNone differType = iota // does not differ differInSize // differs in size - differInMMSourceMTime // differs in multi-master source modtime differInMetadata // differs in metadata differInType // differs in type, exfile/directory differInFirst // only in source (FIRST) differInSecond // only in target (SECOND) + differInMMSourceMTime // differs in multi-master source modtime ) func (d differType) String() string { @@ -91,6 +91,13 @@ func multiMasterModTimeUpdated(src, dst *ClientContent) bool { return false } + _, ok1 := src.UserMetadata[multiMasterSourceModTimeKey] + _, ok2 := dst.UserMetadata[multiMasterSourceModTimeKey] + if !ok1 && !ok2 { + // No multimaster context found, consider src & dst as similar + return false + } + srcOriginLastModified, _ := time.Parse(time.RFC3339Nano, src.UserMetadata[multiMasterSourceModTimeKey]) dstOriginLastModified, _ := time.Parse(time.RFC3339Nano, dst.UserMetadata[multiMasterSourceModTimeKey])