mc mirror watch fix in darwin (#2445)

The event.Path had few prefixes appended in it (only in darwin).
Instead of taking the trimmed directory path, It takes the full path, say '/private/...".
This disturbs the target URL. Which indeed inserts it as a whole '/private/{target_path}',
So trimming the prefixes in the event.path solved it.

Solves:#2443
This commit is contained in:
Praveen raj Mani
2018-05-13 19:34:49 -07:00
committed by Harshavardhana
parent 1b794a4ae1
commit b41b98b04d
+11 -4
View File
@@ -23,6 +23,7 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"
@@ -337,13 +338,19 @@ func (mj *mirrorJob) watchMirror(ctx context.Context, cancelMirror context.Cance
sourceURLFull = tmpSrcURL
}
}
eventPath := event.Path
sourceURL := newClientURL(event.Path)
aliasedPath := strings.Replace(event.Path, sourceURLFull, mj.sourceURL, -1)
if runtime.GOOS == "darwin" {
// Strip the prefixes in the event path. Happens in darwin OS only
eventPath = eventPath[strings.Index(eventPath, sourceURLFull):len(eventPath)]
}
// build target path, it is the relative of the event.Path with the sourceUrl
sourceURL := newClientURL(eventPath)
aliasedPath := strings.Replace(eventPath, sourceURLFull, mj.sourceURL, -1)
// build target path, it is the relative of the eventPath with the sourceUrl
// joined to the targetURL.
sourceSuffix := strings.TrimPrefix(event.Path, sourceURLFull)
sourceSuffix := strings.TrimPrefix(eventPath, sourceURLFull)
//Skip the object, if it matches the Exclude options provided
if matchExcludeOptions(mj.excludeOptions, sourceSuffix) {
continue