mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(extras): only treat an actual link as linking to the source
ResolveLinkTarget falls back to EvalSymlinks, which also resolves a real directory. A real directory reached through a symlinked ancestor of the source then counted as a link to it, so --remove-target --prune failed with "not a symlink" instead of keeping the directory. LinksTo now requires the path itself to be a symlink or junction. Refs #491
This commit is contained in:
@@ -633,7 +633,11 @@ func ClearExtraTarget(file, sourceDir, targetPath, as, mode string, managedFiles
|
||||
// LinksTo reports whether link is a symlink to dir, comparing the link text
|
||||
// too, so a link whose folder has since moved or been deleted still counts.
|
||||
func LinksTo(link, dir string) bool {
|
||||
// ResolveLinkTarget also handles Windows junctions, which Readlink can't read.
|
||||
// ResolveLinkTarget also resolves a real directory, so check the link itself
|
||||
// first; it handles Windows junctions, which Readlink can't read.
|
||||
if !utils.IsSymlinkOrJunction(link) {
|
||||
return false
|
||||
}
|
||||
dest, err := utils.ResolveLinkTarget(link)
|
||||
if err != nil {
|
||||
return false
|
||||
|
||||
@@ -149,3 +149,19 @@ func TestClearExtraTarget_SymlinkTargetThatCannotBeInspectedReportsError(t *test
|
||||
t.Errorf("kept = %v, errs = %v; want an error", kept, errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClearExtraTarget_KeepsRealDirectoryThatResolvesToSource(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
src := filepath.Join(root, "docs")
|
||||
os.MkdirAll(src, 0755)
|
||||
alias := filepath.Join(t.TempDir(), "alias")
|
||||
if err := os.Symlink(root, alias); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, kept, errs := ClearExtraTarget("", src, filepath.Join(alias, "docs"), "", "symlink", nil)
|
||||
|
||||
if !kept || len(errs) > 0 {
|
||||
t.Errorf("kept = %v, errs = %v; want the real directory kept", kept, errs)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user