system: return sys in queueing methods
test / test (push) Successful in 54s Details

This enables building an instance in a single statement.

Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
Ophestra Umiker 2024-10-23 12:34:16 +09:00
parent cafed5f234
commit 20195ece47
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
4 changed files with 30 additions and 14 deletions

View File

@ -9,16 +9,20 @@ import (
) )
// UpdatePerm appends an ephemeral acl update Op. // UpdatePerm appends an ephemeral acl update Op.
func (sys *I) UpdatePerm(path string, perms ...acl.Perm) { func (sys *I) UpdatePerm(path string, perms ...acl.Perm) *I {
sys.UpdatePermType(Process, path, perms...) sys.UpdatePermType(Process, path, perms...)
return sys
} }
// UpdatePermType appends an acl update Op. // UpdatePermType appends an acl update Op.
func (sys *I) UpdatePermType(et Enablement, path string, perms ...acl.Perm) { func (sys *I) UpdatePermType(et Enablement, path string, perms ...acl.Perm) *I {
sys.lock.Lock() sys.lock.Lock()
defer sys.lock.Unlock() defer sys.lock.Unlock()
sys.ops = append(sys.ops, &ACL{et, path, perms}) sys.ops = append(sys.ops, &ACL{et, path, perms})
return sys
} }
type ACL struct { type ACL struct {

View File

@ -9,19 +9,23 @@ import (
) )
// Ensure the existence and mode of a directory. // Ensure the existence and mode of a directory.
func (sys *I) Ensure(name string, perm os.FileMode) { func (sys *I) Ensure(name string, perm os.FileMode) *I {
sys.lock.Lock() sys.lock.Lock()
defer sys.lock.Unlock() defer sys.lock.Unlock()
sys.ops = append(sys.ops, &Mkdir{User, name, perm, false}) sys.ops = append(sys.ops, &Mkdir{User, name, perm, false})
return sys
} }
// Ephemeral ensures the temporary existence and mode of a directory through the life of et. // Ephemeral ensures the temporary existence and mode of a directory through the life of et.
func (sys *I) Ephemeral(et Enablement, name string, perm os.FileMode) { func (sys *I) Ephemeral(et Enablement, name string, perm os.FileMode) *I {
sys.lock.Lock() sys.lock.Lock()
defer sys.lock.Unlock() defer sys.lock.Unlock()
sys.ops = append(sys.ops, &Mkdir{et, name, perm, true}) sys.ops = append(sys.ops, &Mkdir{et, name, perm, true})
return sys
} }
type Mkdir struct { type Mkdir struct {

View File

@ -12,44 +12,50 @@ import (
) )
// CopyFile registers an Op that copies path dst from src. // CopyFile registers an Op that copies path dst from src.
func (sys *I) CopyFile(dst, src string) { func (sys *I) CopyFile(dst, src string) *I {
sys.CopyFileType(Process, dst, src) return sys.CopyFileType(Process, dst, src)
} }
// CopyFileType registers a file copying Op labelled with type et. // CopyFileType registers a file copying Op labelled with type et.
func (sys *I) CopyFileType(et Enablement, dst, src string) { func (sys *I) CopyFileType(et Enablement, dst, src string) *I {
sys.lock.Lock() sys.lock.Lock()
sys.ops = append(sys.ops, &Tmpfile{et, tmpfileCopy, dst, src}) sys.ops = append(sys.ops, &Tmpfile{et, tmpfileCopy, dst, src})
sys.lock.Unlock() sys.lock.Unlock()
sys.UpdatePermType(et, dst, acl.Read) sys.UpdatePermType(et, dst, acl.Read)
return sys
} }
// Link registers an Op that links dst to src. // Link registers an Op that links dst to src.
func (sys *I) Link(oldname, newname string) { func (sys *I) Link(oldname, newname string) *I {
sys.LinkFileType(Process, oldname, newname) return sys.LinkFileType(Process, oldname, newname)
} }
// LinkFileType registers a file linking Op labelled with type et. // LinkFileType registers a file linking Op labelled with type et.
func (sys *I) LinkFileType(et Enablement, oldname, newname string) { func (sys *I) LinkFileType(et Enablement, oldname, newname string) *I {
sys.lock.Lock() sys.lock.Lock()
defer sys.lock.Unlock() defer sys.lock.Unlock()
sys.ops = append(sys.ops, &Tmpfile{et, tmpfileLink, newname, oldname}) sys.ops = append(sys.ops, &Tmpfile{et, tmpfileLink, newname, oldname})
return sys
} }
// Write registers an Op that writes dst with the contents of src. // Write registers an Op that writes dst with the contents of src.
func (sys *I) Write(dst, src string) { func (sys *I) Write(dst, src string) *I {
sys.WriteType(Process, dst, src) return sys.WriteType(Process, dst, src)
} }
// WriteType registers a file writing Op labelled with type et. // WriteType registers a file writing Op labelled with type et.
func (sys *I) WriteType(et Enablement, dst, src string) { func (sys *I) WriteType(et Enablement, dst, src string) *I {
sys.lock.Lock() sys.lock.Lock()
sys.ops = append(sys.ops, &Tmpfile{et, tmpfileWrite, dst, src}) sys.ops = append(sys.ops, &Tmpfile{et, tmpfileWrite, dst, src})
sys.lock.Unlock() sys.lock.Unlock()
sys.UpdatePermType(et, dst, acl.Read) sys.UpdatePermType(et, dst, acl.Read)
return sys
} }
const ( const (

View File

@ -8,11 +8,13 @@ import (
) )
// ChangeHosts appends an X11 ChangeHosts command Op. // ChangeHosts appends an X11 ChangeHosts command Op.
func (sys *I) ChangeHosts(username string) { func (sys *I) ChangeHosts(username string) *I {
sys.lock.Lock() sys.lock.Lock()
defer sys.lock.Unlock() defer sys.lock.Unlock()
sys.ops = append(sys.ops, XHost(username)) sys.ops = append(sys.ops, XHost(username))
return sys
} }
type XHost string type XHost string