mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
* fix(install): keep local installs updatable from any directory and in shape Follow-ups to local-source change detection (#334): - Global installs recorded a relative local path as typed, so `update` and `check` resolved it against whatever directory they ran in and failed with "source path does not exist". Global CLI and dashboard installs now record the absolute path. Project mode keeps the path as written, because .skillshare/config.yaml is shared across machines. - The dashboard installs the root of a directory that also holds child skills as its SKILL.md alone, but `update` re-copied the whole directory, pulling in child skills and unrelated files. Updates now keep that shape. The detection is shared with `check` so both agree on which files belong to the install. * fix(install): never narrow a whole-directory update to SKILL.md alone The SKILL.md-only shape was inferred from a child skill in the source that the recorded hashes lack. A whole-directory install whose source gained a child skill later matched that too, so `update` replaced it with SKILL.md alone and deleted its other files. Decide from the recorded files instead: only an install that recorded SKILL.md alone keeps that shape.
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package install
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// IsSkillFileOnlyInstall reports whether recorded file hashes describe a
|
|
// local install that copied only SKILL.md from a source directory that also
|
|
// holds child skills. The dashboard installs the root of such a collection
|
|
// this way; `install <path>` copies the whole directory, child skills
|
|
// included. source holds the current hashes of the source directory.
|
|
//
|
|
// The recorded files decide: an install that recorded anything besides
|
|
// SKILL.md copied the whole directory, even if child skills were added to
|
|
// the source later, and updating it as SKILL.md alone would delete files.
|
|
func IsSkillFileOnlyInstall(source, recorded map[string]string) bool {
|
|
if _, ok := recorded["SKILL.md"]; !ok || len(recorded) != 1 {
|
|
return false
|
|
}
|
|
for rel := range source {
|
|
if strings.HasSuffix(rel, "/SKILL.md") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// isSkillFileOnlyLocalInstall reports whether the local skill at destPath
|
|
// was installed as its SKILL.md alone, so an update keeps that shape.
|
|
func isSkillFileOnlyLocalInstall(source *Source, destPath, sourceDir string) bool {
|
|
if source.Type != SourceTypeLocalPath {
|
|
return false
|
|
}
|
|
if sourceDir == "" {
|
|
sourceDir = filepath.Dir(destPath)
|
|
}
|
|
rel, err := filepath.Rel(sourceDir, destPath)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
entry := LoadMetadataOrNew(sourceDir).GetByPath(filepath.ToSlash(rel))
|
|
if entry == nil || len(entry.FileHashes) == 0 {
|
|
return false
|
|
}
|
|
hashes, err := ComputeFileHashes(source.Path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return IsSkillFileOnlyInstall(hashes, entry.FileHashes)
|
|
}
|