Skip to content

Commit 8e4d10b

Browse files
committed
fix: correct verbose for rsync, and dep fix
1 parent 40e6e5d commit 8e4d10b

File tree

2 files changed

+66
-13
lines changed

2 files changed

+66
-13
lines changed

cmd/project/functions.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func startProject(networkVolumeId string) error {
295295
fmt.Printf("Activating Python virtual environment %s on Pod %s\n", venvPath, projectPodId)
296296
sshConn.RunCommands([]string{
297297
fmt.Sprint(`
298-
DEPENDENCIES=("wget" "sudo" "lsof" "git" "rsync" "zstd" "jq" "inotify-tools")
298+
DEPENDENCIES=("wget" "sudo" "lsof" "git" "rsync" "zstd" "jq")
299299
300300
function check_and_install_dependencies() {
301301
for dep in "${DEPENDENCIES[@]}"; do
@@ -311,6 +311,19 @@ func startProject(networkVolumeId string) error {
311311
fi
312312
done
313313
314+
# Specifically check for inotifywait command from inotify-tools package
315+
if ! command -v inotifywait &> /dev/null; then
316+
echo "inotifywait could not be found, attempting to install inotify-tools..."
317+
if apt-get install -y inotify-tools; then
318+
echo "inotify-tools installed successfully."
319+
else
320+
echo "Failed to install inotify-tools."
321+
exit 1
322+
fi
323+
else
324+
echo "inotify-tools is already installed."
325+
fi
326+
314327
wget -qO- cli.runpod.net | sudo bash &> /dev/null
315328
}
316329
check_and_install_dependencies`),

cmd/project/ssh.go

+52-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package project
22

33
import (
44
"bufio"
5+
"bytes"
56
"cli/api"
67
"errors"
78
"fmt"
@@ -69,7 +70,7 @@ func (sshConn *SSHConnection) getSshOptions() []string {
6970
}
7071

7172
func (sshConn *SSHConnection) Rsync(localDir string, remoteDir string, quiet bool) error {
72-
rsyncCmdArgs := []string{"-avz", "--no-owner", "--no-group"}
73+
rsyncCmdArgs := []string{"--compress", "--archive", "--verbose", "--no-owner", "--no-group"}
7374

7475
// Retrieve and apply ignore patterns
7576
patterns, err := GetIgnoreList()
@@ -80,21 +81,60 @@ func (sshConn *SSHConnection) Rsync(localDir string, remoteDir string, quiet boo
8081
rsyncCmdArgs = append(rsyncCmdArgs, "--exclude", pat)
8182
}
8283

83-
// Add quiet flag if requested
84-
if quiet {
85-
rsyncCmdArgs = append(rsyncCmdArgs, "--quiet")
86-
}
84+
//Filter from .runpodignore
85+
rsyncCmdArgs = append(rsyncCmdArgs, "--filter=:- .runpodignore")
8786

8887
// Prepare SSH options for rsync
8988
sshOptions := fmt.Sprintf("ssh %s", strings.Join(sshConn.getSshOptions(), " "))
9089
rsyncCmdArgs = append(rsyncCmdArgs, "-e", sshOptions, localDir, fmt.Sprintf("root@%s:%s", sshConn.podIp, remoteDir))
9190

92-
cmd := exec.Command("rsync", rsyncCmdArgs...)
93-
cmd.Stdout = os.Stdout
94-
cmd.Stderr = os.Stderr
91+
// Perform a dry run to check if files need syncing
92+
dryRunArgs := append(rsyncCmdArgs, "--dry-run")
93+
dryRunCmd := exec.Command("rsync", dryRunArgs...)
94+
var dryRunBuf bytes.Buffer
95+
dryRunCmd.Stdout = &dryRunBuf
96+
dryRunCmd.Stderr = &dryRunBuf
97+
if err := dryRunCmd.Run(); err != nil {
98+
return fmt.Errorf("running rsync dry run: %w", err)
99+
}
100+
dryRunOutput := dryRunBuf.String()
101+
102+
// Parse the dry run output to determine if files need syncing
103+
filesNeedSyncing := false
104+
scanner := bufio.NewScanner(strings.NewReader(dryRunOutput))
105+
for scanner.Scan() {
106+
line := scanner.Text()
107+
108+
if line == "" || strings.Contains(line, "sending incremental file list") || strings.Contains(line, "total size is") || strings.Contains(line, "bytes/sec") {
109+
continue
110+
}
111+
112+
filename := filepath.Base(line)
113+
if filename == "" || filename == "." || strings.HasSuffix(line, "/") {
114+
continue
115+
}
95116

96-
if err := cmd.Run(); err != nil {
97-
return fmt.Errorf("executing rsync command: %w", err)
117+
filesNeedSyncing = true
118+
break
119+
}
120+
if err := scanner.Err(); err != nil {
121+
return fmt.Errorf("scanning dry run output: %w", err)
122+
}
123+
124+
// Add quiet flag if requested
125+
if quiet {
126+
rsyncCmdArgs = append(rsyncCmdArgs, "--quiet")
127+
}
128+
129+
if filesNeedSyncing {
130+
fmt.Println("Syncing files...")
131+
132+
cmd := exec.Command("rsync", rsyncCmdArgs...)
133+
cmd.Stdout = os.Stdout
134+
cmd.Stderr = os.Stderr
135+
if err := cmd.Run(); err != nil {
136+
return fmt.Errorf("executing rsync command: %w", err)
137+
}
98138
}
99139

100140
return nil
@@ -133,7 +173,7 @@ func hasChanges(localDir string, lastSyncTime time.Time) (bool, string) {
133173

134174
func (sshConn *SSHConnection) SyncDir(localDir string, remoteDir string) {
135175
syncFiles := func() {
136-
fmt.Println("Syncing files...")
176+
// fmt.Println("Syncing files...")
137177
err := sshConn.Rsync(localDir, remoteDir, true)
138178
if err != nil {
139179
fmt.Printf(" error: %v\n", err)
@@ -148,7 +188,7 @@ func (sshConn *SSHConnection) SyncDir(localDir string, remoteDir string) {
148188
time.Sleep(100 * time.Millisecond)
149189
hasChanged, firstModifiedFile := hasChanges(localDir, lastSyncTime)
150190
if hasChanged {
151-
fmt.Printf("Found changes in %s\n", firstModifiedFile)
191+
fmt.Printf("Local changes detected in %s\n", firstModifiedFile)
152192
syncFiles()
153193
lastSyncTime = time.Now()
154194
}

0 commit comments

Comments
 (0)