Give a directory's contents before the directory, matched by user
Review round 1: the contents are now given before the directory's own owner changes, so a walk that fails leaves the directory as it was and the next apply walks again; an entry gone meanwhile is nothing to give. An entry is matched by its user alone: one of another user is left with everything below it, and one given the new user gets the new group only where its group was the previous group. A test now applies a directory whose owner changed, with stand-ins for the chowns, and shows the contents given first and a placed child left. Builds: design 47 H2 H-A-550, H-A-554 (2)
This commit is contained in:
@@ -17,6 +17,9 @@ import (
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
)
|
||||
|
||||
// fchownDirectory gives a mesh directory its owner through its descriptor; a variable so a test sees it without being root.
|
||||
var fchownDirectory = unix.Fchown
|
||||
|
||||
// meshDirsByDescriptor says this system can open a directory component by component without following a link.
|
||||
const meshDirsByDescriptor = true
|
||||
|
||||
@@ -88,18 +91,20 @@ func applyMeshDirectory(r *declaration.Directory, out Outcome, mode os.FileMode,
|
||||
}
|
||||
ownedAlready := !chown || (beforeUID == uid && beforeGID == gid)
|
||||
if !ownedAlready {
|
||||
if err := unix.Fchown(fd, uid, gid); err != nil {
|
||||
// The contents first (H-A-554 (2)): a walk that fails leaves the directory's owner as it was, so the next apply
|
||||
// walks again.
|
||||
if existed && !created {
|
||||
if _, err := giveContents(walk.At, [2]int{beforeUID, beforeGID}, [2]int{uid, gid}, placed); err != nil {
|
||||
return out, err
|
||||
}
|
||||
}
|
||||
if err := fchownDirectory(fd, uid, gid); err != nil {
|
||||
return out, fmt.Errorf("cannot give %s to %q: %w", r.Path, r.Owner, &os.PathError{Op: "chown", Path: r.Path, Err: err})
|
||||
}
|
||||
// A chown may take the setgid bit: the mode is set again after it.
|
||||
if err := unix.Fchmod(fd, unixDirMode(mode)); err != nil {
|
||||
return out, &os.PathError{Op: "chmod", Path: r.Path, Err: err}
|
||||
}
|
||||
if existed && !created {
|
||||
if _, err := giveContents(walk.At, [2]int{beforeUID, beforeGID}, [2]int{uid, gid}, placed); err != nil {
|
||||
return out, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read back, from the descriptor that was changed.
|
||||
|
||||
Reference in New Issue
Block a user