Files
skillshare/cmd/skillshare/helpers.go
T
Willie b93ad3ffe4 refactor: split main.go into separate command files
Split the 1585-line main.go into focused modules:
- main.go: entry point and command routing
- init.go: initialization command
- sync.go: sync command
- status.go: status command
- target.go: target management commands
- diff.go: diff command
- backup.go: backup and restore commands
- pull.go: pull command
- doctor.go: diagnostic command
- helpers.go: shared utility functions

No functional changes - purely structural refactoring for maintainability.
2026-01-14 22:16:24 +08:00

49 lines
865 B
Go

package main
import (
"io"
"os"
"path/filepath"
)
// copyDir copies a directory recursively.
func copyDir(src, dst string) 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)
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
}