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

+41
View File
@@ -23,30 +23,37 @@ func privateDirectories(path string) error {
if !filepath.IsAbs(path) {
return errors.New("directory path must be absolute")
}
current := "/"
for _, component := range strings.Split(strings.TrimPrefix(filepath.Clean(path), "/"), "/") {
if component == "" {
continue
}
current = filepath.Join(current, component)
if err := os.Mkdir(current, 0700); err != nil && !errors.Is(err, os.ErrExist) {
return err
}
st, err := os.Lstat(current)
if err != nil {
return err
}
if !st.IsDir() {
return fmt.Errorf("directory contains a symlink or non-directory: %s", current)
}
}
return nil
}
func checkMount(root string, writable bool) error {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return err
}
defer f.Close()
scan := bufio.NewScanner(f)
found := false
@@ -55,36 +62,45 @@ func checkMount(root string, writable bool) error {
if len(parts) != 2 {
continue
}
fields, after := strings.Fields(parts[0]), strings.Fields(parts[1])
if len(fields) < 6 || len(after) < 2 {
continue
}
mount := unescapeMount(fields[4])
if mount == root {
if after[0] != "ceph" && after[0] != "fuse.ceph-fuse" {
return fmt.Errorf("%s is not a CephFS mount", root)
}
if writable && !strings.Contains(","+fields[5]+",", ",rw,") {
return fmt.Errorf("target %s must be mounted read-write", root)
}
found = true
} else if beneath(root, mount) {
return fmt.Errorf("nested mount %s below %s is unsupported", mount, root)
}
}
if err := scan.Err(); err != nil {
return err
}
if !found {
return fmt.Errorf("%s must be a dedicated CephFS filesystem-root mount", root)
}
resolved, err := filepath.EvalSymlinks(root)
if err != nil {
return err
}
if resolved != root {
return errors.New("mount path must not contain symlinks")
}
return nil
}
@@ -97,9 +113,11 @@ func xattr(path, key string) ([]byte, error) {
if err != nil {
return nil, err
}
if n > 1<<20 {
return nil, fmt.Errorf("xattr too large: %s", key)
}
b := make([]byte, n)
n, err = syscall.Getxattr(path, key, b)
if errors.Is(err, syscall.ERANGE) {
@@ -108,8 +126,10 @@ func xattr(path, key string) ([]byte, error) {
if err != nil {
return nil, err
}
return b[:n], nil
}
return nil, errors.New("xattr changed repeatedly")
}
@@ -128,9 +148,11 @@ func walkTree(ctx context.Context, root string, visitDir func(string) error, vis
if err := ctx.Err(); err != nil {
return err
}
if depth > 128 {
return errors.New("directory depth exceeds supported limit (128)")
}
if visitDir != nil {
if err := visitDir(path); errors.Is(err, fs.SkipDir) {
return nil
@@ -138,10 +160,12 @@ func walkTree(ctx context.Context, root string, visitDir func(string) error, vis
return err
}
}
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
for {
batch, readErr := f.ReadDir(128)
@@ -149,9 +173,11 @@ func walkTree(ctx context.Context, root string, visitDir func(string) error, vis
if err := ctx.Err(); err != nil {
return err
}
if e.Name() == ".snap" {
continue
}
child := filepath.Join(path, e.Name())
if e.IsDir() {
if err := walk(child, depth+1); err != nil {
@@ -162,19 +188,23 @@ func walkTree(ctx context.Context, root string, visitDir func(string) error, vis
if err != nil {
return err
}
if err = visitFile(child, info); err != nil {
return err
}
}
}
if errors.Is(readErr, io.EOF) {
return nil
}
if readErr != nil {
return readErr
}
}
}
return walk(root, 0)
}
@@ -185,13 +215,16 @@ func clearQuotas(ctx context.Context, root string) error {
if err != nil {
return fmt.Errorf("read quota %s: %w", path, err)
}
if string(old) == "0" {
continue
}
if err := syscall.Setxattr(path, key, []byte("0"), 0); err != nil {
return fmt.Errorf("clear quota %s: %w", path, err)
}
}
return nil
})
}
@@ -202,33 +235,41 @@ func quotas(ctx context.Context, src, dst string, verify bool) error {
if err != nil {
return err
}
target := filepath.Join(dst, rel)
st, err := os.Lstat(target)
if err != nil {
return err
}
if !st.IsDir() {
return fmt.Errorf("quota target is not a real directory: %s", target)
}
for _, key := range quotaKeys {
value, err := xattr(path, key)
if err != nil {
return fmt.Errorf("source quota %s %s: %w", path, key, err)
}
actual, err := xattr(target, key)
if err != nil {
return fmt.Errorf("target quota %s %s: %w", target, key, err)
}
if string(value) == string(actual) {
continue
}
if verify {
return fmt.Errorf("quota mismatch: %s %s", rel, key)
}
if err := syscall.Setxattr(target, key, value, 0); err != nil {
return fmt.Errorf("set quota %s %s: %w", target, key, err)
}
}
return nil
})
}