package install import ( "fmt" "os" "path/filepath" "strconv" "time" "skillshare/internal/sourcefs" "skillshare/internal/sourcewalk" ) // removeInSource removes destPath, below the skills source sourceDir, through // the source-write handle, so a link at or above it is refused instead of // replaced. func removeInSource(sourceDir, destPath string, follow *sourcewalk.Follow) error { src, err := sourcefs.Open(sourceDir, follow) if err != nil { return err } defer src.Close() rel, err := src.Rel(destPath) if err != nil { return err } return src.RemoveAll(rel) } // swapStagedIntoSource replaces destPath, below the skills source sourceDir, // with the staged directory. The rename crosses the source's edge, so the // in-source side is checked through the handle first. Only a cross-device // rename falls back to a copy, and that copy also goes through the handle; // every other failure, a refused link included, is returned as is. The old // skill is kept under a sibling name until replacement succeeds and restored // if copying or moving fails. func swapStagedIntoSource(sourceDir, staged, destPath string, follow *sourcewalk.Follow) error { src, err := sourcefs.Open(sourceDir, follow) if err != nil { return err } defer src.Close() rel, err := src.Rel(destPath) if err != nil { return err } if err := src.CheckNoLink(rel); err != nil { return err } backup := "" if _, err := src.Lstat(rel); err == nil { // ".old." keeps the backup apart from the ".skillshare-.