Skip to content

Commit

Permalink
Bump version: 0.1.0 → 0.1.1
Browse files Browse the repository at this point in the history
fix: Deleted files were not being cleaned up when syncing
  • Loading branch information
arzkar committed Oct 4, 2023
1 parent 9fd5e85 commit a9d4bc9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
23 changes: 0 additions & 23 deletions .bumpversion.cfg

This file was deleted.

9 changes: 9 additions & 0 deletions .git-utils-bump.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bumpversion]
current_version = 0.1.1
commit = True
tag = False
tag_format = v{tag}

[bumpversion:file:cmd/root.go]
search = adb-sync v{current_version}
replace = adb-sync v{new_version}
27 changes: 27 additions & 0 deletions cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ func pull(sourcePath string, destinationPath string, dryRun bool, checksum bool,
return
}

destinationFiles, err := utils.GetFilesRecursive(destinationPath, "push")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

// Create a map of destination files for faster lookups
destinationFileMap := make(map[string]bool)
for _, destFile := range destinationFiles {
destinationFileMap[destFile] = true
}

for _, file := range sourceFiles {
relativePath, err := filepath.Rel(sourcePath, file)
if err != nil {
Expand All @@ -88,5 +100,20 @@ func pull(sourcePath string, destinationPath string, dryRun bool, checksum bool,
} else {
fmt.Printf("Skipped: %s -> %s (File already exists and is up to date)\n\n", color.RedString(sanitizedSourceFile), color.RedString(destFile))
}

// Remove the destination file & its parent from the map if it exists
delete(destinationFileMap, destFile)
delete(destinationFileMap, filepath.Dir(destFile))
}

// Remove any remaining files in the destination directory that were not in the source
for destFile := range destinationFileMap {
fmt.Printf("Removing: %s\n", color.YellowString(destFile))
if !dryRun {
err := os.Remove(destFile)
if err != nil {
fmt.Printf("Failed to remove file: %v\n", err)
}
}
}
}
30 changes: 30 additions & 0 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package cmd

import (
"fmt"
"os/exec"
"path/filepath"
"strings"

"github.com/arzkar/adb-sync/utils"

Expand Down Expand Up @@ -62,6 +64,18 @@ func push(sourcePath string, destinationPath string, dryRun bool, checksum bool,
return
}

destinationFiles, err := utils.GetFilesRecursive(destinationPath, "pull")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}

// Create a map of destination files for faster lookups
destinationFileMap := make(map[string]bool)
for _, destFile := range destinationFiles {
destinationFileMap[destFile] = true
}

for _, file := range sourceFiles {
relativePath, err := filepath.Rel(sourcePath, file)
if err != nil {
Expand All @@ -78,5 +92,21 @@ func push(sourcePath string, destinationPath string, dryRun bool, checksum bool,
} else {
fmt.Printf("Skipped: %s -> %s (File already exists and is up to date)\n\n", color.RedString(file), color.RedString(sanitizedDestFile))
}
// Remove the destination file & its parent from the map if it exists
delete(destinationFileMap, destFile)
delete(destinationFileMap, filepath.Dir(destFile))
}

// Remove any remaining files in the destination directory that were not in the source
for destFile := range destinationFileMap {
sanitizedDestFile := utils.SanitizeAndroidPath(destFile)
fmt.Printf("Removing: %s\n", color.YellowString(sanitizedDestFile))
if !dryRun {
output, err := exec.Command("adb", "shell", "rm", fmt.Sprintf(`"%s"`, sanitizedDestFile)).CombinedOutput()
if err != nil {
errorMessage := strings.TrimSpace(string(output))
fmt.Printf("Failed to remove file: %s\nError: %s\n", color.RedString(sanitizedDestFile), color.RedString(errorMessage))
}
}
}
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
var rootCmd = &cobra.Command{
Use: "adb-sync",
Short: "A CLI to sync between android & local system using adb",
Long: `adb-sync v0.1.0
Long: `adb-sync v0.1.1
Copyright (c) Arbaaz Laskar <[email protected]>
A CLI to sync between android & local system using adb
Expand Down

0 comments on commit a9d4bc9

Please sign in to comment.