mirror: Add timestamp check similar to aws s3 sync (#2188)
Currently `mc mirror` requires source to be uploaded only if the size is different than the object on remote server. This PR adds support to check for last modified time of the source object as well such that we upload if there are timestamp differences as well. Fixes #2187
This commit is contained in:
@@ -91,6 +91,8 @@ func (d diffMessage) String() string {
|
||||
msg = console.Colorize("DiffType", "! "+d.SecondURL)
|
||||
case differInSize:
|
||||
msg = console.Colorize("DiffSize", "! "+d.SecondURL)
|
||||
case differInTime:
|
||||
msg = console.Colorize("DiffTime", "! "+d.SecondURL)
|
||||
default:
|
||||
fatalIf(errDummy().Trace(d.FirstURL, d.SecondURL),
|
||||
"Unhandled difference between `"+d.FirstURL+"` and `"+d.SecondURL+"`.")
|
||||
@@ -198,6 +200,7 @@ 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))
|
||||
|
||||
URLs := ctx.Args()
|
||||
firstURL := URLs.Get(0)
|
||||
|
||||
+17
-2
@@ -29,6 +29,7 @@ type differType int
|
||||
const (
|
||||
differInNone differType = iota // does not differ
|
||||
differInSize // differs in size
|
||||
differInTime // differs in time
|
||||
differInType // only in source
|
||||
differInFirst // only in target
|
||||
differInSecond // differs in type, exfile/directory
|
||||
@@ -40,6 +41,8 @@ func (d differType) String() string {
|
||||
return ""
|
||||
case differInSize:
|
||||
return "size"
|
||||
case differInTime:
|
||||
return "time"
|
||||
case differInType:
|
||||
return "type"
|
||||
case differInFirst:
|
||||
@@ -161,9 +164,10 @@ func difference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isRe
|
||||
if normalizedExpected == normalizedCurrent {
|
||||
srcType, tgtType := srcCtnt.Type, tgtCtnt.Type
|
||||
srcSize, tgtSize := srcCtnt.Size, tgtCtnt.Size
|
||||
srcTime, tgtTime := srcCtnt.Time, tgtCtnt.Time
|
||||
if srcType.IsRegular() && !tgtType.IsRegular() ||
|
||||
!srcType.IsRegular() && tgtType.IsRegular() {
|
||||
// Type differes. Source is never a directory.
|
||||
// Type differs. Source is never a directory.
|
||||
diffCh <- diffMessage{
|
||||
FirstURL: srcCtnt.URL.String(),
|
||||
SecondURL: tgtCtnt.URL.String(),
|
||||
@@ -171,7 +175,9 @@ func difference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isRe
|
||||
firstContent: srcCtnt,
|
||||
secondContent: tgtCtnt,
|
||||
}
|
||||
} else if (srcType.IsRegular() && tgtType.IsRegular()) && srcSize != tgtSize {
|
||||
continue
|
||||
}
|
||||
if (srcType.IsRegular() && tgtType.IsRegular()) && srcSize != tgtSize {
|
||||
// Regular files differing in size.
|
||||
diffCh <- diffMessage{
|
||||
FirstURL: srcCtnt.URL.String(),
|
||||
@@ -180,6 +186,15 @@ func difference(sourceClnt, targetClnt Client, sourceURL, targetURL string, isRe
|
||||
firstContent: srcCtnt,
|
||||
secondContent: tgtCtnt,
|
||||
}
|
||||
} else if srcTime.After(tgtTime) {
|
||||
// Regular files differing in timestamp.
|
||||
diffCh <- diffMessage{
|
||||
FirstURL: srcCtnt.URL.String(),
|
||||
SecondURL: tgtCtnt.URL.String(),
|
||||
Diff: differInTime,
|
||||
firstContent: srcCtnt,
|
||||
secondContent: tgtCtnt,
|
||||
}
|
||||
}
|
||||
// No differ
|
||||
if returnSimilar {
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ func deltaSourceTarget(sourceURL string, targetURL string, isForce bool, isFake
|
||||
case differInType:
|
||||
URLsCh <- URLs{Error: errInvalidTarget(diffMsg.SecondURL)}
|
||||
continue
|
||||
case differInSize:
|
||||
case differInSize, differInTime:
|
||||
if !isForce && !isFake {
|
||||
// Size differs and force not set
|
||||
URLsCh <- URLs{Error: errOverWriteNotAllowed(diffMsg.SecondURL)}
|
||||
|
||||
Reference in New Issue
Block a user