All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m8s
Test / Hakurei (push) Successful in 2m59s
Test / Hpkg (push) Successful in 3m56s
Test / Sandbox (race detector) (push) Successful in 4m28s
Test / Hakurei (race detector) (push) Successful in 5m4s
Test / Flake checks (push) Successful in 1m21s
The mutex is not really doing anything, none of these methods make sense when called concurrently anyway. The copylocks analysis is still satisfied by the noCopy struct. 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 appends [HardlinkOp] to [I] the [Process] criteria.
|
|
func (sys *I) Link(oldname, newname string) *I { return sys.LinkFileType(Process, oldname, newname) }
|
|
|
|
// LinkFileType appends [HardlinkOp] to [I].
|
|
func (sys *I) LinkFileType(et Enablement, oldname, newname string) *I {
|
|
sys.ops = append(sys.ops, &HardlinkOp{et, newname, oldname})
|
|
return sys
|
|
}
|
|
|
|
// HardlinkOp maintains a hardlink until its [Enablement] is no longer satisfied.
|
|
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) {
|
|
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) }
|