mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* fix(plugin): let OMP and Pi plugin updates through without uninstalling (#833) Every OMP update was blocked, because OMP's native upgrade replaces cache folders that projects outside its inventory may still use. The only way to move an OMP binding to a new commit was to uninstall first. An update now runs the same pair a source change already uses: the scoped removal adapter (cache kept), then an install under a fresh marketplace and cache identity. A refresh always takes a new identity, because OMP installs from the catalog it cached when the marketplace was added, and that catalog still names the old version. If the removal cannot be verified, the update is blocked; update --all still skips it with the reason. Pi was blocked whenever the catalog plugin name differed from its package.json name. That happens after an upstream npm rename, for example when npm refused the original name. Pi installs by path, and Skillshare keys the binding by the catalog name, so the npm name never reaches either, and the check only stopped working installs. Updating one package across several Agents stopped every Agent as soon as one was blocked. Each failing Agent is now reported with its reason while the others update, and the command exits non-zero. A single --target, or a package with no other Agent to update, stays blocked as before, so a dry-run still fails when nothing would update. * fix(plugin): let one update --all refresh several OMP packages Every OMP removal proves itself against a fingerprint of the whole native registry and lock. In a single update --all plan, the first package's removal and reinstall rewrite those shared files. The second package's removal therefore saw "OMP native files changed", so only one OMP package could update per run. The same applied to a sync that replaced the sources of several OMP packages. A removal now also fingerprints only its own installation: its registry entry, its lock entry, its package manifest and its runtime link. After an earlier change in the same apply has written to that OMP target, the removal re-reads the files and runs every ownership check again. It goes ahead only if that own fingerprint still matches the preview. A change outside Skillshare to the package's own entries still blocks it. Without an earlier write in the apply, the full-file check is unchanged. The fake OMP in the tests now merges installs into the registry and lock and lists them in a stable order, as the real one keeps other plugins.
121 lines
3.9 KiB
Go
121 lines
3.9 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// Native install recursively removes its runtime destination before linking the
|
|
// cache. Require an absent destination, including undeclared/transitive packages.
|
|
func ompEmptyRuntime(path string) error {
|
|
if err := ompSafePath(path); err != nil {
|
|
return err
|
|
}
|
|
if _, err := os.Lstat(path); !os.IsNotExist(err) {
|
|
return fmt.Errorf("OMP runtime destination is not verified empty: %s", path)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Preview may count only the exact link a verified earlier removal will free.
|
|
// Apply still requires an empty destination after executing that removal.
|
|
func ompPreviewRuntime(path string, cleanup *ompRemoval) error {
|
|
if cleanup != nil && cleanup.linkPresent && cleanup.link == path {
|
|
if err := ompSafePath(filepath.Dir(path)); err != nil {
|
|
return err
|
|
}
|
|
if target, err := os.Readlink(path); err == nil && target == cleanup.target {
|
|
return nil
|
|
}
|
|
}
|
|
return ompEmptyRuntime(path)
|
|
}
|
|
|
|
func (s *Service) prepareOMPInstall(ctx context.Context, h Host, c *Change, cleanup *ompRemoval) {
|
|
check := func() error {
|
|
ref := c.Binding.Commit
|
|
if ref == "" {
|
|
ref = c.Binding.SourceRef
|
|
}
|
|
root, source, releaseSource, err := acquireRef(ctx, c.Binding.Source, ref)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer releaseSource()
|
|
d, err := discoverRoot(root, source, c.Binding.Entry)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.Digest != c.Binding.Digest {
|
|
return fmt.Errorf("OMP source changed; preview again")
|
|
}
|
|
for _, candidate := range d.Candidates {
|
|
if candidate.Name != c.Binding.Plugin {
|
|
continue
|
|
}
|
|
module, _, err := ompRemovalPackage(filepath.Join(root, candidate.pathFor("omp")), candidate.Name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
runtimeRoot := filepath.Dir(filepath.Dir(h.ompCacheRoot))
|
|
if s.ProjectRoot != "" {
|
|
runtimeRoot = filepath.Join(s.ProjectRoot, ".omp", "plugins")
|
|
}
|
|
c.ompRuntimePath = filepath.Join(runtimeRoot, "node_modules", filepath.FromSlash(module))
|
|
return ompPreviewRuntime(c.ompRuntimePath, cleanup)
|
|
}
|
|
return fmt.Errorf("OMP source no longer provides the reviewed plugin")
|
|
}
|
|
if err := check(); err != nil {
|
|
c.Action, c.Message, c.MessageKey = "blocked", err.Error(), "plugins.error.ompRuntimeSafety"
|
|
}
|
|
}
|
|
|
|
// Reinstalls use a new marketplace/cache identity instead of replacing the
|
|
// retained cache an invisible project can still use. Preview chooses the same
|
|
// first free identity until native state changes and invalidates its revision.
|
|
// A refresh never keeps its identity: OMP installs from the catalog cached when
|
|
// the marketplace was added, which still names the old version.
|
|
func ompFreshCache(h Host, c *Change) error {
|
|
if err := ompSafePath(h.ompCacheRoot); err != nil {
|
|
return err
|
|
}
|
|
if v := c.Binding.Version; v != "" && (filepath.Base(v) != v || strings.ContainsAny(v, "\\/\r\n\x00")) {
|
|
return fmt.Errorf("unsafe OMP cache version")
|
|
}
|
|
original := c.ID
|
|
name, _, ok := strings.Cut(original, "@")
|
|
if !ok || !validOMPName(name) {
|
|
return fmt.Errorf("invalid OMP plugin identity")
|
|
}
|
|
first := 0
|
|
if c.ompRefresh {
|
|
first = 1
|
|
}
|
|
for attempt := first; attempt < 100; attempt++ {
|
|
candidate := original
|
|
if attempt > 0 {
|
|
candidate = name + "@skillshare-" + hash([]byte(fmt.Sprintf("%s\x00reinstall\x00%d", original, attempt)))[:16]
|
|
}
|
|
info, err := os.Lstat(ompCachePath(h.ompCacheRoot, candidate, c.Binding.Version))
|
|
if os.IsNotExist(err) {
|
|
if attempt > 0 {
|
|
_, market, _ := strings.Cut(candidate, "@")
|
|
if _, registered := h.Marketplaces[market]; registered {
|
|
continue
|
|
}
|
|
c.ID, c.Binding.ID = candidate, candidate
|
|
c.Message, c.MessageKey = "Installs into a new cache identity; retained cache used by other projects is not changed.", "plugins.note.ompFreshCache"
|
|
}
|
|
return nil
|
|
}
|
|
if err != nil || !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
|
|
return fmt.Errorf("unreadable or linked OMP cache destination")
|
|
}
|
|
}
|
|
return fmt.Errorf("no free OMP cache identity")
|
|
}
|