Don't overwrite symlinks if file already exists

This commit is contained in:
2023-10-03 14:57:16 -05:00
committed by John K. Luebs
parent 997ff5bdf6
commit 99e4dcae00

View File

@@ -753,8 +753,7 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
fullPath := joinPath(top, remoteEntry.Path) fullPath := joinPath(top, remoteEntry.Path)
if remoteEntry.IsLink() { if remoteEntry.IsLink() {
stat, err := os.Lstat(fullPath) if stat, _ := os.Lstat(fullPath); stat != nil {
if stat != nil {
if stat.Mode()&os.ModeSymlink != 0 { if stat.Mode()&os.ModeSymlink != 0 {
isRegular, link, err := Readlink(fullPath) isRegular, link, err := Readlink(fullPath)
if err == nil && link == remoteEntry.Link && !isRegular { if err == nil && link == remoteEntry.Link && !isRegular {
@@ -763,11 +762,16 @@ func (manager *BackupManager) Restore(top string, revision int, inPlace bool, qu
} }
} }
if !overwrite {
LOG_WERROR(allowFailures, "DOWNLOAD_OVERWRITE",
"File %s already exists. Please specify the -overwrite option to overwrite", remoteEntry.Path)
continue
}
os.Remove(fullPath) os.Remove(fullPath)
} }
err = os.Symlink(remoteEntry.Link, fullPath) if err := os.Symlink(remoteEntry.Link, fullPath); err != nil {
if err != nil {
LOG_ERROR("RESTORE_SYMLINK", "Can't create symlink %s: %v", remoteEntry.Path, err) LOG_ERROR("RESTORE_SYMLINK", "Can't create symlink %s: %v", remoteEntry.Path, err)
return 0 return 0
} }