diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-09 00:14:33 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-09 00:14:33 +0300 |
| commit | 756ae621bd97a8b776fefb15e5e7e2292f98ee45 (patch) | |
| tree | b454f958e6aef70bf7ca40dcbc106323cee2a42f /internal/resource/file | |
| parent | 3f8b79f2b1384e3abc2b1bb2fe913688c7ec251c (diff) | |
dependencies
Diffstat (limited to 'internal/resource/file')
| -rw-r--r-- | internal/resource/file/file.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/internal/resource/file/file.go b/internal/resource/file/file.go index 88b0bca..2dc1df5 100644 --- a/internal/resource/file/file.go +++ b/internal/resource/file/file.go @@ -12,9 +12,12 @@ import ( opt "codeberg.org/snonux/gonf/api/options" "codeberg.org/snonux/gonf/internal/resource" + "codeberg.org/snonux/gonf/internal/resource/embed" ) type File struct { + embed.DependsOn + embed.Absence resource resource.Resource path string content string @@ -22,7 +25,6 @@ type File struct { user string group string mode os.FileMode - absent bool } // SetContent implements opt.Contented. Setting literal content clears any @@ -48,9 +50,6 @@ func (f *File) SetGroup(group string) { f.group = group } // SetMode implements opt.Moded. func (f *File) SetMode(mode os.FileMode) { f.mode = mode } -// SetAbsent implements opt.Absentable. -func (f *File) SetAbsent() { f.absent = true } - func build(path string, opts ...opt.Option) (*File, error) { curr, err := user.Current() if err != nil { @@ -74,7 +73,7 @@ func build(path string, opts ...opt.Option) (*File, error) { // apply performs the idempotent OS work for f without registering a // resource. func (f *File) apply() error { - if f.absent { + if f.Absent { return ensureAbsent(f.targetPath()) } @@ -225,7 +224,7 @@ func Present(path string, opts ...opt.Option) resource.Resource { } f.resource = resource.Register("File", f.targetPath(), - resource.ApplierFunc(func() error { return f.apply() })) + resource.ApplierFunc(func() error { return f.apply() }), f.DependsOn.IDs...) return f.resource } |
