From b41b98b04d8eb63195479c72dd082dce1e760a7e Mon Sep 17 00:00:00 2001 From: Praveen raj Mani Date: Mon, 14 May 2018 08:04:49 +0530 Subject: [PATCH] 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 --- cmd/mirror-main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index d215a786..c40fa25a 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -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