mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(plugin): read plugin sources through their real path on macOS (#544)
Adding a plugin from a Git URL to Oh My Pi on macOS was always blocked with "linked or non-directory OMP path component", which the dashboard shows as "The reviewed OMP runtime destination must be verified empty". The source is cloned into os.MkdirTemp, which lives under /var/folders, and /var links to /private/var. The OMP install check reads the source's package.json through ompSafePath, which rejects any linked component, so Skillshare's own temp clone failed it. A local source under a linked parent failed the same way. acquireRef now hands callers the resolved root of the temp clone and of a local directory, while the recorded source stays as given. Links inside the source are still handled as before; cleanup still removes the original temp directory.
This commit is contained in:
@@ -181,6 +181,21 @@ func TestOMPAddInstallsFromTheSnapshotMarketplace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// macOS temp clones live under /var, a link to /private/var; the source location is not an OMP path.
|
||||
func TestOMPAddReadsSourceBehindLinkedDirectory(t *testing.T) {
|
||||
agents := &fakeAgents{version: "1.0.0"}
|
||||
s := agents.service(t)
|
||||
source := fixture(t)
|
||||
link := filepath.Join(t.TempDir(), "linked")
|
||||
if err := os.Symlink(filepath.Dir(source), link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p, err := s.Preview(context.Background(), Request{Action: "add", Source: filepath.Join(link, filepath.Base(source)), Targets: []string{"omp"}})
|
||||
if err != nil || len(p.Changes) != 1 || p.Changes[0].Action != "install" {
|
||||
t.Fatalf("source behind a linked directory was not installable: %+v %v", p, err)
|
||||
}
|
||||
}
|
||||
|
||||
// omp deletes a plugin's cache folder on uninstall and replaces it on upgrade, checking only the
|
||||
// registries visible from its working directory. A project elsewhere that installed the same
|
||||
// identity is invisible, so Skillshare never runs those commands. Scoped removal uses
|
||||
|
||||
@@ -48,7 +48,12 @@ func acquireRef(ctx context.Context, source, ref string) (string, string, func()
|
||||
return "", "", cleanup, fmt.Errorf("source ref requires a remote Git source")
|
||||
}
|
||||
p, err := filepath.Abs(source)
|
||||
return p, p, cleanup, err
|
||||
if err != nil {
|
||||
return "", "", cleanup, err
|
||||
}
|
||||
// Read from the real location: a linked parent (macOS /var -> /private/var) is not plugin content.
|
||||
root, err := filepath.EvalSymlinks(p)
|
||||
return root, p, cleanup, err
|
||||
}
|
||||
if isNpmSource(source) {
|
||||
return "", "", cleanup, fmt.Errorf("npm packages can't be previewed: Pi downloads them when it installs them. Add one to a Pi target with: skillshare plugin add %s --target pi", source)
|
||||
@@ -65,6 +70,11 @@ func acquireRef(ctx context.Context, source, ref string) (string, string, func()
|
||||
return "", "", cleanup, err
|
||||
}
|
||||
cleanup = func() { _ = os.RemoveAll(root) }
|
||||
clone, err := filepath.EvalSymlinks(root)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return "", "", func() {}, err
|
||||
}
|
||||
_, err = runCommand(ctx, "", nil, "git", "-c", "core.hooksPath=/dev/null", "clone", "--depth", "1", "--", source, root)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
@@ -79,7 +89,7 @@ func acquireRef(ctx context.Context, source, ref string) (string, string, func()
|
||||
return "", "", func() {}, fmt.Errorf("resolve source ref: %w", err)
|
||||
}
|
||||
}
|
||||
return root, source, cleanup, nil
|
||||
return clone, source, cleanup, nil
|
||||
}
|
||||
|
||||
// treeDigest includes safe relative links, leaves out unsafe ones and rejects special files.
|
||||
|
||||
Reference in New Issue
Block a user