style: add blank lines between declarations and statement blocks

Separate top-level declarations and multi-line statements with blank
lines, keeping an "if err != nil" check next to the statement it
belongs to. Expand semicolon one-liners, group the nativeTransport
fields by purpose, and format the cgo preamble as readable C.
Apart from the expanded one-liners and the C preamble, the change
is whitespace only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 18:36:19 +01:00
1 parent ec0297fd23
commit a6fda8f8d3
25 files changed
+929 -41

No files matched your search

+25
View File
@@ -36,17 +36,21 @@ func TestRsyncRetriesOnlyObservedHardlinkEEXIST(t *testing.T) {
if calls == 1 {
return &ProcessError{Name: "rsync", Err: exitErr, Diagnostic: tc.diagnostic}
}
return nil
})
err := (Rsync{Exec: x, Log: io.Discard}).Copy(context.Background(), "/a", "/b")
if calls != tc.attempts {
t.Fatalf("attempts: %d", calls)
}
if (err == nil) != (tc.attempts == 2) {
t.Fatalf("unexpected result: %v", err)
}
})
}
calls := 0
x := executorFunc(func(context.Context, io.Writer, string, ...string) error { calls++; return context.Canceled })
err := (Rsync{Exec: x}).Copy(context.Background(), "/a", "/b")
@@ -59,79 +63,99 @@ func TestRsyncDetectsSameSizeSameMtimeAndPreservesLinks(t *testing.T) {
if _, err := exec.LookPath("rsync"); err != nil {
t.Skip("rsync is not installed")
}
src, dst := t.TempDir(), t.TempDir()
path := filepath.Join(src, "file with spaces\nand newline")
if err := os.WriteFile(path, []byte("AAAA"), 0640); err != nil {
t.Fatal(err)
}
if err := os.Link(path, filepath.Join(src, "hardlink")); err != nil {
t.Fatal(err)
}
if err := os.Symlink("nonexistent", filepath.Join(src, "dangling")); err != nil {
t.Fatal(err)
}
if err := syscall.Setxattr(path, "user.cephmig", []byte("test"), 0); err != nil {
t.Fatal(err)
}
r := Rsync{Exec: Process{Stderr: io.Discard}, Log: io.Discard}
ctx := context.Background()
if err := r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err := r.Verify(ctx, src, dst); err != nil {
t.Fatal(err)
}
a, _ := os.Stat(filepath.Join(dst, "hardlink"))
b, _ := os.Stat(filepath.Join(dst, filepath.Base(path)))
if !os.SameFile(a, b) {
t.Fatal("hardlinks were split")
}
st, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if err = os.WriteFile(path, []byte("BBBB"), 0640); err != nil {
t.Fatal(err)
}
if err = os.Chtimes(path, st.ModTime(), st.ModTime()); err != nil {
t.Fatal(err)
}
if err = r.Verify(ctx, src, dst); err == nil {
t.Fatal("checksum verification missed changed bytes")
}
if err = os.WriteFile(filepath.Join(dst, "obsolete"), []byte("extra"), 0600); err != nil {
t.Fatal(err)
}
if err = r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err = r.Verify(ctx, src, dst); err != nil {
t.Fatal(err)
}
if _, err = os.Stat(filepath.Join(dst, "obsolete")); !os.IsNotExist(err) {
t.Fatal("obsolete target file survived")
}
got, err := xattr(filepath.Join(dst, "hardlink"), "user.cephmig")
if err != nil || string(got) != "test" {
t.Fatalf("xattr: %q, %v", got, err)
}
}
func TestProcessCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.Canceled {
t.Fatalf("got %v", err)
}
ctx, cancel = context.WithTimeout(context.Background(), 50*time.Millisecond)
defer cancel()
start := time.Now()
if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.DeadlineExceeded {
t.Fatalf("got %v", err)
}
if time.Since(start) > 2*time.Second {
t.Fatal("cancellation was too slow")
}
}
func TestRsyncUsesIncrementalSafeOptions(t *testing.T) {
joined := strings.Join((Rsync{BandwidthKiB: 1024}).args("/source", "/target"), " ")
for _, required := range []string{"-aHAXS", "--checksum", "--delete-during", "--no-whole-file", "--fsync", "--bwlimit=1024", "--filter=-x ceph.*"} {
@@ -139,6 +163,7 @@ func TestRsyncUsesIncrementalSafeOptions(t *testing.T) {
t.Fatalf("missing %s", required)
}
}
for _, bad := range []string{"--inplace", "--delete-before", "--delete-after", "--delay-updates"} {
if strings.Contains(joined, bad) {
t.Fatalf("unsafe option %s", bad)