mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
filepath.Walk/WalkDir silently skip symlinked root directories because os.Lstat sees the root as a non-directory symlink and never enters it. This affected update, uninstall, reconcile, and server handlers when the source directory was a symlink (common with dotfiles managers). Extract ResolveSymlink() from sync.go into internal/utils/path.go and apply it at every filepath.Walk/WalkDir callsite on source/target dirs. Also add containment guards to resolveGroupSkills (uninstall) and resolveGroupUpdatable (update) to reject group directories that are symlinks pointing outside the source tree.
37 lines
987 B
Go
37 lines
987 B
Go
package utils
|
|
|
|
import (
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// PathsEqual compares two paths for equality.
|
|
// On Windows, paths are compared case-insensitively since NTFS is case-insensitive.
|
|
// On Unix systems, paths are compared exactly.
|
|
func PathsEqual(a, b string) bool {
|
|
if runtime.GOOS == "windows" {
|
|
return strings.EqualFold(a, b)
|
|
}
|
|
return a == b
|
|
}
|
|
|
|
// PathHasPrefix checks if path starts with prefix.
|
|
// On Windows, comparison is case-insensitive.
|
|
// On Unix systems, comparison is exact.
|
|
// ResolveSymlink resolves symlinks on a path so filepath.Walk enters
|
|
// symlinked directories. Falls back to the original path on error.
|
|
func ResolveSymlink(path string) string {
|
|
if resolved, err := filepath.EvalSymlinks(path); err == nil {
|
|
return resolved
|
|
}
|
|
return path
|
|
}
|
|
|
|
func PathHasPrefix(path, prefix string) bool {
|
|
if runtime.GOOS == "windows" {
|
|
return strings.HasPrefix(strings.ToLower(path), strings.ToLower(prefix))
|
|
}
|
|
return strings.HasPrefix(path, prefix)
|
|
}
|