Skip to content

Commit

Permalink
sender: report i/o error when files vanish or cannot be accessed
Browse files Browse the repository at this point in the history
fixes #27
  • Loading branch information
stapelberg committed Feb 23, 2025
1 parent 4bc6396 commit 8149b79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 2 additions & 4 deletions integration/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ func TestErrors(t *testing.T) {
}

output := buf.String()
if want := "no such file or directory"; !strings.Contains(output, want) {
t.Fatalf("rsync output unexpectedly did not contain %q:\n%s", want, output)
}
if want := nonExistant; !strings.Contains(output, want) {
t.Logf("output:\n%s\n(end of output)", output)
if want := "some files could not be transferred (code 23)"; !strings.Contains(output, want) {
t.Fatalf("rsync output unexpectedly did not contain %q:\n%s", want, output)
}
}
Expand Down
11 changes: 9 additions & 2 deletions internal/sender/flist.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (st *Transfer) SendFileList(trimPrefix, localDir string, opts *rsyncopts.Op
// error flag, but traversal should continue

st.Logger.Printf("sendFileList()")
ioErrors := int32(0)
// TODO: handle |root| referring to an individual file, symlink or special (skip)
for _, requested := range paths {
st.Logger.Printf(" path %q (local dir %q)", requested, localDir)
Expand All @@ -79,7 +80,14 @@ func (st *Transfer) SendFileList(trimPrefix, localDir string, opts *rsyncopts.Op
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
// st.logger.Printf("filepath.WalkFn(path=%s)", path)
if err != nil {
return err
if os.IsNotExist(err) {
st.Logger.Printf("file vanished: %v", err)
} else {
st.Logger.Printf("lstat: %v", err)
}
// set the I/O error flag, but keep walking
ioErrors = 1
return nil
}

// Only ever transmit long names, like openrsync
Expand Down Expand Up @@ -267,7 +275,6 @@ func (st *Transfer) SendFileList(trimPrefix, localDir string, opts *rsyncopts.Op
}
fec.WriteInt32(endOfSet)

const ioErrors = 0
fec.WriteInt32(ioErrors)

if err := st.Conn.WriteString(fec.String()); err != nil {
Expand Down

0 comments on commit 8149b79

Please sign in to comment.