From 47c4c25d8b3a99bc73e3004b2dabfe6356749957 Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Tue, 4 Jun 2019 21:57:10 -0400 Subject: [PATCH] Fixed a bug that restoring files doesn't work due to missing parent directory The root cause was path.Dir can't handle Windows paths that use \ as the separator. --- src/duplicacy_backupmanager.go | 3 ++- src/duplicacy_utils_others.go | 4 ++++ src/duplicacy_utils_windows.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/duplicacy_backupmanager.go b/src/duplicacy_backupmanager.go index 41e52d4..42bf281 100644 --- a/src/duplicacy_backupmanager.go +++ b/src/duplicacy_backupmanager.go @@ -899,7 +899,8 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu continue } } else { - err = os.MkdirAll(path.Dir(fullPath), 0744) + parent, _ := SplitDir(fullPath) + err = os.MkdirAll(parent, 0744) if err != nil { LOG_ERROR("DOWNLOAD_MKDIR", "Failed to create directory: %v", err) } diff --git a/src/duplicacy_utils_others.go b/src/duplicacy_utils_others.go index fc35134..1465fee 100644 --- a/src/duplicacy_utils_others.go +++ b/src/duplicacy_utils_others.go @@ -88,3 +88,7 @@ func (entry *Entry) SetAttributesToFile(fullPath string) { func joinPath(components ...string) string { return path.Join(components...) } + +func SplitDir(fullPath string) (dir string, file string) { + return path.Split(fullPath) +} diff --git a/src/duplicacy_utils_windows.go b/src/duplicacy_utils_windows.go index 6a9b066..ec5c171 100644 --- a/src/duplicacy_utils_windows.go +++ b/src/duplicacy_utils_windows.go @@ -126,3 +126,8 @@ func joinPath(components ...string) string { } return combinedPath } + +func SplitDir(fullPath string) (dir string, file string) { + i := strings.LastIndex(fullPath, "\\") + return fullPath[:i+1], fullPath[i+1:] +}