Documentation ¶
Overview ¶
Package nugo provides a graph with unix style modes.
The graph is a set of linked nodes
root | +-- child sibling sibling | | * +-- child sibling ...
Each node references its parent aswell. In addition to the standard unix permission rwxrwxrwx another set of rwx are added to indicate anonymous access control. Permission bits for "Other" means other authenticated.
rwxrwxrwxrwx ModePerm n u g o | | | | aNonymous --+ | | | User -----+ | | Group --------+ | Other -----------+
Operations on the graph are not synchronized, this is left to any system using it.
Example ¶
root := NewRoot("/") root.Make("etc") tmp := root.Make("tmp") tmp.Make("y.txt") root.Walk(NamePrinter(os.Stdout))
Output: /etc /tmp /tmp/y.txt
Example (GraphManipulation) ¶
root := NewRootNode("/", ModeSort) root.MakeAll("etc", "tmp", "usr/") tmp, _ := root.Find("/tmp") tmp.MakeAll("y.txt", "dir") tmp.DelChild("dir") root.Walk(func(Child *Node, abspath string, w *Walker) { fmt.Fprintln(os.Stdout, abspath) if abspath == "/tmp/y.txt" { w.Stop() } })
Output: /etc /tmp /tmp/y.txt
Example (Sorted) ¶
root := NewRootNode("/", ModeSort) root.MakeAll("c", "b", "a") b, _ := root.Find("/b") b.MakeAll("2", "1", "3", "0", "2.5") root.Walk(NamePrinter(os.Stdout))
Output: /a /b /b/0 /b/1 /b/2 /b/2.5 /b/3 /c
Example (SortedDistinct) ¶
root := NewRootNode("/", ModeSort|ModeDistinct) b := root.Make("b") b.MakeAll("2", "1", "1", "2") root.Make("a") root.Walk(NamePrinter(os.Stdout))
Output: /a /b /b/1 /b/2
Index ¶
- type Node
- func (me *Node) AbsPath() string
- func (me *Node) Add(children ...*Node)
- func (me *Node) CheckDir() error
- func (me *Node) CheckRoot() error
- func (me *Node) Copy() *Node
- func (me *Node) DelChild(name string) *Node
- func (me *Node) Find(abspath string) (*Node, error)
- func (me *Node) FirstChild() *Node
- func (me *Node) IsDir() bool
- func (me *Node) IsRoot() bool
- func (me *Node) LastChild() *Node
- func (me *Node) Make(name string) *Node
- func (me *Node) MakeAll(names ...string) []*Node
- func (my *Node) SetMode(Mode NodeMode)
- func (my *Node) SetPerm(perm NodeMode)
- func (my *Node) SetSeal(uid, gid int, Mode NodeMode)
- func (me *Node) String() string
- func (me *Node) UnsetMode(mask NodeMode)
- func (me *Node) Walk(fn Visitor)
- type NodeMode
- type Seal
- type Sealed
- type Visitor
- type Walker
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node struct { Name string Seal Content interface{} sync.RWMutex Parent *Node Child *Node Sibling *Node }
Node names and links a sibling and a child.
func NewRoot ¶
NewRoot returns a new node with the name as is. It's the callers responsibility to make sure every basename is safe, Valid abspaths are "/" or "/mnt/usb". Defaults to mode ModeDir | ModeRoot.
func NewRootNode ¶
NewRootNode returns a root node with the additional given mode.
Example ¶
NewRootNode is a way to root a tree at a given point. Only difference from NewNode is it can contain / in the name.
root := NewRoot("/mnt/usb") a := root.Make("a") a.MakeAll("file.txt") root.Make("b") root.Walk(NamePrinter(os.Stdout))
Output: /mnt/usb/a /mnt/usb/a/file.txt /mnt/usb/b
func (*Node) Add ¶
Add adds each child in sequence according to the NodeMode of the parent node. Add blocks if another add is in progress. For ModeDistinct an existing node with the same name is replaced.
func (*Node) DelChild ¶
DelChild removes the first child with the given name and returns the removed node
Example ¶
root := NewRoot("/") root.MakeAll("etc", "bin", "tmp", "usr/") tmp, _ := root.Find("/tmp") tmp.MakeAll("y.txt", "dir") root.DelChild("etc") root.DelChild("no such") bin, _ := root.Find("/bin") bin.DelChild("no such") tmp.DelChild("dir") tmp.DelChild("x.gz") root.Walk(NamePrinter(os.Stdout))
Output: /bin /tmp /tmp/y.txt /usr%2F
func (*Node) Find ¶
Find returns the node matching the absolute path. This node must be a root node.
func (*Node) FirstChild ¶
FirstChild returns the first child or nil if there are no children.
Example (ListAllChildren) ¶
root := NewRoot("/") root.MakeAll("a", "b") c := root.FirstChild() for { if c == nil { break } fmt.Fprintln(os.Stdout, c.Name) c = c.Sibling }
Output: a b
func (*Node) Make ¶
Make creates and adds the named child returning the new node. See Add method for mode inheritence.
func (*Node) SetMode ¶ added in v0.3.1
SetMode sets mode of this node.
Example ¶
n := NewNode("node") n.Mode = 01755 fmt.Println(n) n.SetMode(ModeDir) fmt.Println(n)
Output: ---xrwxr-xr-x 0 0 node d--xrwxr-xr-x 0 0 node
type Visitor ¶
Visitor is called during a walk with a specific node and the absolute path to that node. Use the given Walker to stop if needed. For root nodes the parent is nil.
func NamePrinter ¶
NamePrinter writes abspath to the given writer.
func NodeLogger ¶
NodeLogger logs permissions and ownership with each node
Example ¶
root := NewRootNode("/", ModeSort|ModeDistinct) root.SetSeal(1, 1, 01755) tmp := root.Make("tmp") tmp.Make("sub") l := fox.NewSyncLog(os.Stdout) root.Walk(NodeLogger(l))
Output: d--xrwxr-xr-x 1 1 /tmp d--xrwxr-xr-x 1 1 /tmp/sub
func NodePrinter ¶
NodePrinter writes permissions and ownership with each node
Example ¶
root := NewRootNode("/", ModeSort|ModeDistinct) root.SetSeal(1, 1, 01755) root.Make("etc") // inherits parent mode root.Walk(NodePrinter(os.Stdout))
Output: d--xrwxr-xr-x 1 1 /etc