40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/novox/mesh-host/internal/apply"
|
|
"github.com/novox/mesh-host/internal/link"
|
|
"github.com/novox/mesh-host/internal/store"
|
|
)
|
|
|
|
// judgeDirectories judges every directory of the declaration this node keeps, read-only (novox/hq issue 358): which
|
|
// the walk that follows no link another account could make would refuse. Nothing is made, chmodded or chowned.
|
|
func judgeDirectories(statePath string) (string, error) {
|
|
d, err := declaredNow(statePath, nil)
|
|
if errors.Is(err, store.ErrNothingDeclared) {
|
|
return "", errors.New("this node keeps no declaration, so it is declared no directory")
|
|
}
|
|
if err != nil {
|
|
return "", fmt.Errorf("what runs on this node does not read: %w", err)
|
|
}
|
|
return apply.JudgeDirectories(d), nil
|
|
}
|
|
|
|
// judgeDirectoriesFrom is judgeDirectories as the controller asks it over the link.
|
|
func judgeDirectoriesFrom(statePath string) link.JudgeDirectoriesFunc {
|
|
return func(string) (string, error) { return judgeDirectories(statePath) }
|
|
}
|
|
|
|
// judgeDirectoriesCommand is `nox-mesh-host judge-directories` at this machine, as root: the same judgement, for a
|
|
// machine the controller cannot ask.
|
|
func judgeDirectoriesCommand(opts options) error {
|
|
said, err := judgeDirectories(opts.state)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintln(opts.out, said)
|
|
return nil
|
|
}
|