fix hako sync
This commit is contained in:
parent
30a510cb17
commit
cd1f23527e
3 changed files with 145 additions and 11 deletions
34
commands.go
34
commands.go
|
@ -130,6 +130,7 @@ func psCommand() error {
|
|||
}
|
||||
|
||||
func syncCommand() error {
|
||||
// TODO use the container for the currently working directory instead of just the first one in the filter...
|
||||
output, err := runCommandOutput("docker", "ps", "-a", "--filter", "name=hako-", "--format", "{{.Names}}")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -160,44 +161,65 @@ func syncCommand() error {
|
|||
}
|
||||
|
||||
func syncFiles(srcDir, destDir string) error {
|
||||
gitignore, err := NewGitIgnore()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse .gitignore: %v", err)
|
||||
}
|
||||
|
||||
return filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to walk %q: %v", path, err)
|
||||
}
|
||||
|
||||
relPath, err := filepath.Rel(srcDir, path)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("failed to calculate relative path for %q: %v", path, err)
|
||||
}
|
||||
|
||||
if relPath == ".git" || relPath == ".gitignore" {
|
||||
// Skip .git directory and its contents
|
||||
if relPath == ".git" {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
// Skip files that start with .git (like .gitignore, .gitmodules, etc.)
|
||||
if strings.HasPrefix(filepath.Base(relPath), ".git") {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if the file should be ignored according to .gitignore
|
||||
if gitignore.IsIgnored(relPath) {
|
||||
if info.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
destPath := filepath.Join(destDir, relPath)
|
||||
|
||||
if info.IsDir() {
|
||||
return os.MkdirAll(destPath, info.Mode())
|
||||
}
|
||||
|
||||
fmt.Println("cp", path, destPath)
|
||||
srcFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to open %s: %v\n", path, err)
|
||||
return nil
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
destFile, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
return err
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to create %s: %v\n", destPath, err)
|
||||
return nil
|
||||
}
|
||||
defer destFile.Close()
|
||||
|
||||
_, err = io.Copy(destFile, srcFile)
|
||||
return err
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to copy %s to %s: %v\n", path, destPath, err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue