mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(extras): keep a target in config when it cannot be inspected
ClearExtraTarget treated every Lstat failure on a symlink-mode target as "nothing there", so a permission or I/O error made the CLI drop the target from the config and report nothing pruned. Only a missing target is now forgotten; other errors are returned so the config is kept for a retry. Refs #491
This commit is contained in:
@@ -617,8 +617,14 @@ func ClearExtraTarget(file, sourceDir, targetPath, as, mode string, managedFiles
|
||||
return 0, false, nil
|
||||
}
|
||||
if mode == "symlink" && !LinksTo(targetPath, sourceDir) {
|
||||
_, err := os.Lstat(targetPath)
|
||||
return 0, err == nil, nil
|
||||
// Only a missing target is safe to forget; any other error must stop
|
||||
// the caller before it drops the target from the config.
|
||||
if _, err := os.Lstat(targetPath); err == nil {
|
||||
return 0, true, nil
|
||||
} else if !os.IsNotExist(err) {
|
||||
return 0, false, []string{err.Error()}
|
||||
}
|
||||
return 0, false, nil
|
||||
}
|
||||
pruned, errors = PruneExtraTargetFiles(targetPath, sourceDir, mode, managedFiles)
|
||||
return pruned, false, errors
|
||||
|
||||
@@ -138,3 +138,14 @@ func TestPruneExtraTargetFiles_SymlinkRequiresSymlink(t *testing.T) {
|
||||
t.Errorf("local file must be preserved, stat err = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClearExtraTarget_SymlinkTargetThatCannotBeInspectedReportsError(t *testing.T) {
|
||||
notDir := filepath.Join(t.TempDir(), "file")
|
||||
os.WriteFile(notDir, []byte("x"), 0644)
|
||||
|
||||
_, kept, errs := ClearExtraTarget("", t.TempDir(), filepath.Join(notDir, "docs"), "", "symlink", nil)
|
||||
|
||||
if kept || len(errs) == 0 {
|
||||
t.Errorf("kept = %v, errs = %v; want an error", kept, errs)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user