diff --git a/core-test b/core-test index 7a211f99..9b746b57 100755 Binary files a/core-test and b/core-test differ diff --git a/internal/cmd/docs/cmd_scan.go b/internal/cmd/docs/cmd_scan.go index 8257c944..d88ad278 100644 --- a/internal/cmd/docs/cmd_scan.go +++ b/internal/cmd/docs/cmd_scan.go @@ -9,6 +9,7 @@ import ( "github.com/host-uk/core/internal/cmd/workspace" "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" "github.com/host-uk/core/pkg/repos" ) @@ -93,28 +94,29 @@ func scanRepoDocs(repo *repos.Repo) RepoDocInfo { // Check for README.md readme := filepath.Join(repo.Path, "README.md") - if _, err := os.Stat(readme); err == nil { + if io.Local.IsFile(readme) { info.Readme = readme info.HasDocs = true } // Check for CLAUDE.md claudeMd := filepath.Join(repo.Path, "CLAUDE.md") - if _, err := os.Stat(claudeMd); err == nil { + if io.Local.IsFile(claudeMd) { info.ClaudeMd = claudeMd info.HasDocs = true } // Check for CHANGELOG.md changelog := filepath.Join(repo.Path, "CHANGELOG.md") - if _, err := os.Stat(changelog); err == nil { + if io.Local.IsFile(changelog) { info.Changelog = changelog info.HasDocs = true } // Recursively scan docs/ directory for .md files docsDir := filepath.Join(repo.Path, "docs") - if _, err := os.Stat(docsDir); err == nil { + // Check if directory exists by listing it + if _, err := io.Local.List(docsDir); err == nil { filepath.WalkDir(docsDir, func(path string, d fs.DirEntry, err error) error { if err != nil { return nil @@ -137,11 +139,3 @@ func scanRepoDocs(repo *repos.Repo) RepoDocInfo { return info } - -func copyFile(src, dst string) error { - data, err := os.ReadFile(src) - if err != nil { - return err - } - return os.WriteFile(dst, data, 0644) -} diff --git a/internal/cmd/docs/cmd_sync.go b/internal/cmd/docs/cmd_sync.go index b4ce4888..2cbfb4dc 100644 --- a/internal/cmd/docs/cmd_sync.go +++ b/internal/cmd/docs/cmd_sync.go @@ -1,12 +1,12 @@ package docs import ( - "os" "path/filepath" "strings" "github.com/host-uk/core/pkg/cli" "github.com/host-uk/core/pkg/i18n" + "github.com/host-uk/core/pkg/io" ) // Flag variables for sync command @@ -127,9 +127,9 @@ func runDocsSync(registryPath string, outputDir string, dryRun bool) error { repoOutDir := filepath.Join(outputDir, outName) // Clear existing directory - os.RemoveAll(repoOutDir) + io.Local.Delete(repoOutDir) // Recursive delete - if err := os.MkdirAll(repoOutDir, 0755); err != nil { + if err := io.Local.EnsureDir(repoOutDir); err != nil { cli.Print(" %s %s: %s\n", errorStyle.Render("✗"), info.Name, err) continue } @@ -139,8 +139,10 @@ func runDocsSync(registryPath string, outputDir string, dryRun bool) error { for _, f := range info.DocsFiles { src := filepath.Join(docsDir, f) dst := filepath.Join(repoOutDir, f) - os.MkdirAll(filepath.Dir(dst), 0755) - if err := copyFile(src, dst); err != nil { + // Ensure parent dir + io.Local.EnsureDir(filepath.Dir(dst)) + + if err := io.Copy(io.Local, src, io.Local, dst); err != nil { cli.Print(" %s %s: %s\n", errorStyle.Render("✗"), f, err) } } diff --git a/pkg/io/io.go b/pkg/io/io.go index 9870ce7e..a1f63075 100644 --- a/pkg/io/io.go +++ b/pkg/io/io.go @@ -2,6 +2,7 @@ package io import ( "os" + "strings" coreerr "github.com/host-uk/core/pkg/framework/core" "github.com/host-uk/core/pkg/io/local" @@ -146,10 +147,24 @@ func (m *MockMedium) FileSet(path, content string) error { return m.Write(path, content) } -// Delete removes a file or empty directory from the mock filesystem. +// Delete removes a file or directory recursively from the mock filesystem. func (m *MockMedium) Delete(path string) error { + // Delete exact match delete(m.Files, path) delete(m.Dirs, path) + + // Delete all children (naive string prefix check) + prefix := path + "/" + for k := range m.Files { + if strings.HasPrefix(k, prefix) { + delete(m.Files, k) + } + } + for k := range m.Dirs { + if strings.HasPrefix(k, prefix) { + delete(m.Dirs, k) + } + } return nil } diff --git a/pkg/io/local/client.go b/pkg/io/local/client.go index 1dd3f7dd..7a43c7f6 100644 --- a/pkg/io/local/client.go +++ b/pkg/io/local/client.go @@ -168,13 +168,13 @@ func (m *Medium) FileSet(relativePath, content string) error { return m.Write(relativePath, content) } -// Delete removes a file or empty directory. +// Delete removes a file or directory recursively. func (m *Medium) Delete(relativePath string) error { fullPath, err := m.path(relativePath) if err != nil { return err } - return os.Remove(fullPath) + return os.RemoveAll(fullPath) } // Rename moves or renames a file.