All checks were successful
Test / Create distribution (push) Successful in 52s
Test / Sandbox (push) Successful in 3m30s
Test / Hakurei (push) Successful in 5m40s
Test / Sandbox (race detector) (push) Successful in 6m30s
Test / Hpkg (push) Successful in 7m21s
Test / Hakurei (race detector) (push) Successful in 3m22s
Test / Flake checks (push) Successful in 2m2s
None of these are valid with their zero value, and the implementations assume they are created by the builder methods. They are by all means an implementation detail and exporting them makes no sense. Signed-off-by: Ophestra <cat@gensokyo.uk>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package system
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// Link calls LinkFileType with the [Process] criteria.
|
|
func (sys *I) Link(oldname, newname string) *I { return sys.LinkFileType(Process, oldname, newname) }
|
|
|
|
// LinkFileType maintains a hardlink until its [Enablement] is no longer satisfied.
|
|
func (sys *I) LinkFileType(et Enablement, oldname, newname string) *I {
|
|
sys.ops = append(sys.ops, &hardlinkOp{et, newname, oldname})
|
|
return sys
|
|
}
|
|
|
|
// hardlinkOp implements [I.LinkFileType].
|
|
type hardlinkOp struct {
|
|
et Enablement
|
|
dst, src string
|
|
}
|
|
|
|
func (l *hardlinkOp) Type() Enablement { return l.et }
|
|
|
|
func (l *hardlinkOp) apply(*I) error {
|
|
msg.Verbose("linking", l)
|
|
return newOpError("hardlink", os.Link(l.src, l.dst), false)
|
|
}
|
|
|
|
func (l *hardlinkOp) revert(_ *I, ec *Criteria) error {
|
|
if ec.hasType(l.Type()) {
|
|
msg.Verbosef("removing hard link %q", l.dst)
|
|
return newOpError("hardlink", os.Remove(l.dst), true)
|
|
} else {
|
|
msg.Verbosef("skipping hard link %q", l.dst)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (l *hardlinkOp) Is(o Op) bool {
|
|
target, ok := o.(*hardlinkOp)
|
|
return ok && l != nil && target != nil && *l == *target
|
|
}
|
|
|
|
func (l *hardlinkOp) Path() string { return l.src }
|
|
func (l *hardlinkOp) String() string { return fmt.Sprintf("%q from %q", l.dst, l.src) }
|