mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
An orchestrator repository containing a root SKILL.md together with child SKILL.md directories (e.g. iOfficeAI/OfficeCLI) previously installed as a single bundled directory that mirrored the git clone: copying the root dragged every child skill dir into it, and children marked selected were silently skipped as "included in parent" while their computed dest paths were never written to. Make each discovered skill a first-class install: - New copyDirExcluding() skips subdirectories by slash-normalized relative path, so a skill directory is copied without duplicating any nested skill that is itself being installed elsewhere. - installFromDiscoveryImpl computes the descendant skill paths of the skill currently being copied and passes them as excludes. For the root of an orchestrator repo this drops every child skill dir; for a non-root skill it drops any sub-skill nested inside it. - installSelectedSkills stops skipping children after the root is installed. The existing dest-path logic already places each child under <parentName>/<childName>, so the children are written as siblings to the root install. After the fix, a multi-skill repo with N skills produces N independent installed directories discoverable by sync, updatable individually. Refs: #124
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package install
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// copyDir recursively copies src into dst, skipping any `.git` directory.
|
|
func copyDir(src, dst string) error {
|
|
return copyDirExcluding(src, dst, nil)
|
|
}
|
|
|
|
// copyDirExcluding recursively copies src into dst, skipping any `.git`
|
|
// directory and any subdirectory whose slash-normalized path relative to src
|
|
// appears in excludes. The excludes keys must use forward slashes (e.g.
|
|
// "skills/officecli-pptx"). Passing a nil or empty map is equivalent to
|
|
// copyDir.
|
|
func copyDirExcluding(src, dst string, excludes map[string]bool) error {
|
|
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
relPath, _ := filepath.Rel(src, path)
|
|
dstPath := filepath.Join(dst, relPath)
|
|
|
|
// Skip .git directory
|
|
if info.IsDir() && info.Name() == ".git" {
|
|
return filepath.SkipDir
|
|
}
|
|
|
|
// Skip excluded subdirectories (e.g. child skill dirs when copying
|
|
// the root of an orchestrator repo so they do not duplicate into the
|
|
// root install).
|
|
if len(excludes) > 0 && info.IsDir() && relPath != "." {
|
|
if excludes[filepath.ToSlash(relPath)] {
|
|
return filepath.SkipDir
|
|
}
|
|
}
|
|
|
|
if info.IsDir() {
|
|
return os.MkdirAll(dstPath, info.Mode())
|
|
}
|
|
|
|
return copyFile(path, dstPath)
|
|
})
|
|
}
|
|
|
|
// copyFile copies a single file
|
|
func copyFile(src, dst string) error {
|
|
srcFile, err := os.Open(src)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer srcFile.Close()
|
|
|
|
srcInfo, err := srcFile.Stat()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
dstFile, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, srcInfo.Mode())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer dstFile.Close()
|
|
|
|
_, err = io.Copy(dstFile, srcFile)
|
|
return err
|
|
}
|