Repository: rclone/rclone
File: fs/operations/operations.go (Go)

Code before:
// Unlike Equal, it does not consider size or checksum, as these do not apply to directories.
func DirsEqual(ctx context.Context, src, dst fs.Directory, opt DirsEqualOpt) (equal bool) {
	if dst == nil {
		return false
	}
	ci := fs.GetConfig(ctx)
	if ci.SizeOnly || ci.Immutable || ci.UseServerModTime || opt.ModifyWindow == fs.ModTimeNotSupported {
		return true
	}
	if ci.IgnoreTimes {
		return false
	}
	if !(opt.SetDirModtime || opt.SetDirMetadata) {
		return true
	}
	srcModTime, dstModTime := src.ModTime(ctx), dst.ModTime(ctx)
	if srcModTime.IsZero() || dstModTime.IsZero() {
		return false
	}
	dt := dstModTime.Sub(srcModTime)
	if dt < opt.ModifyWindow && dt > -opt.ModifyWindow {
		fs.Debugf(dst, "dir modification time the same (differ by %s, within tolerance %s)", dt, opt.ModifyWindow)
		return true
	}
	if ci.UpdateOlder && dt >= opt.ModifyWindow {
		fs.Debugf(dst, "Destination is newer than source, skipping")
		return true
	}
	return false
}

// sizeDiffers compare the size of src and dst taking into account the
// various ways of ignoring sizes
func sizeDiffers(ctx context.Context, src, dst fs.ObjectInfo) bool {
	ci := fs.GetConfig(ctx)
	if ci.IgnoreSize || src.Size() < 0 || dst.Size() < 0 {
		return false
	}
	return src.Size() != dst.Size()
}

var checksumWarning sync.Once

// options for equal function()
type equalOpt struct {
	sizeOnly          bool // if set only check size
	checkSum          bool // if set check checksum+size instead of modtime+size
	updateModTime     bool // if set update the modtime if hashes identical and checking with modtime+size
	forceModTimeMatch bool // if set assume modtimes match
}


Review comment (suggestion):
We should probably mention `Destination directory is newer...`

Code after:
// Unlike Equal, it does not consider size or checksum, as these do not apply to directories.
func DirsEqual(ctx context.Context, src, dst fs.Directory, opt DirsEqualOpt) (equal bool) {
	if dst == nil {
		return false
	}
	ci := fs.GetConfig(ctx)
	if ci.SizeOnly || ci.Immutable || ci.IgnoreExisting || opt.ModifyWindow == fs.ModTimeNotSupported {
		return true
	}
	if ci.IgnoreTimes {
		return false
	}
	if !(opt.SetDirModtime || opt.SetDirMetadata) {
		return true
	}
	srcModTime, dstModTime := src.ModTime(ctx), dst.ModTime(ctx)
	if srcModTime.IsZero() || dstModTime.IsZero() {
		return false
	}
	dt := dstModTime.Sub(srcModTime)
	if dt < opt.ModifyWindow && dt > -opt.ModifyWindow {
		fs.Debugf(dst, "Directory modification time the same (differ by %s, within tolerance %s)", dt, opt.ModifyWindow)
		return true
	}
	if ci.UpdateOlder && dt >= opt.ModifyWindow {
		fs.Debugf(dst, "Destination directory is newer than source, skipping")
		return true
	}
	return false
}

// sizeDiffers compare the size of src and dst taking into account the
// various ways of ignoring sizes
func sizeDiffers(ctx context.Context, src, dst fs.ObjectInfo) bool {
	ci := fs.GetConfig(ctx)
	if ci.IgnoreSize || src.Size() < 0 || dst.Size() < 0 {
		return false
	}
	return src.Size() != dst.Size()
}

var checksumWarning sync.Once

// options for equal function()
type equalOpt struct {
	sizeOnly          bool // if set only check size
	checkSum          bool // if set check checksum+size instead of modtime+size
	updateModTime     bool // if set update the modtime if hashes identical and checking with modtime+size
	forceModTimeMatch bool // if set assume modtimes match
}