mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Implements rollout steps 1 and 2 of proposals/274-skillfollow.md. Nothing follows a link or parses .skillfollow yet. Step 1: doctor reports first-level symlinks and junctions in the skills source as info, in text and JSON, without following them. Step 2a: internal/sourcewalk owns traversal of the skills source. Thirteen raw walks move onto it with identical behavior, and a go/parser ratchet fails the tests on any new unclassified walk. Step 2b: internal/sourcefs wraps an os.Root opened at the skills source and refuses any write whose path has a link component. The six write sites the proposal found in review move onto it, including the cross-device copy fallback, and a second ratchet covers raw os write calls. The only behavior change is that an explicit path crossing a link inside the source is refused instead of written through. Refs #274 Release-As: 0.24.3
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package install
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"skillshare/internal/sourcefs"
|
|
)
|
|
|
|
// 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) error {
|
|
src, err := sourcefs.Open(sourceDir)
|
|
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.
|
|
func swapStagedIntoSource(sourceDir, staged, destPath string) error {
|
|
src, err := sourcefs.Open(sourceDir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer src.Close()
|
|
rel, err := src.Rel(destPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := src.RemoveAll(rel); err != nil {
|
|
return fmt.Errorf("failed to remove existing skill: %w", err)
|
|
}
|
|
if err := src.MoveIn(staged, rel); err != nil {
|
|
if !sourcefs.IsCrossDevice(err) {
|
|
return fmt.Errorf("failed to move updated skill: %w", err)
|
|
}
|
|
if err := src.CopyIn(staged, rel); err != nil {
|
|
return fmt.Errorf("failed to copy updated skill: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|