Download this file
| 1 | //go:build linux && rootrunner |
| 2 | |
| 3 | package rootstate |
| 4 | |
| 5 | import ( |
| 6 | "github.com/carlosframework/platform/internal/safefile" |
| 7 | "os" |
| 8 | ) |
| 9 | |
| 10 | type faultStore struct { |
| 11 | Store |
| 12 | step func(string, string, func() error) error |
| 13 | } |
| 14 | |
| 15 | func WithWriteFault(s Store, step func(string, string, func() error) error) Store { |
| 16 | return faultStore{Store: s, step: step} |
| 17 | } |
| 18 | |
| 19 | func (s faultStore) Write(name string, body []byte) error { |
| 20 | d, ok := s.Store.(*directory) |
| 21 | if !ok { |
| 22 | return os.ErrPermission |
| 23 | } |
| 24 | return d.write(name, body, func(fd int, name string, body []byte, mode os.FileMode) error { |
| 25 | return safefile.WriteAtFault(fd, name, body, mode, func(stage string, op func() error) error { return s.step(name, stage, op) }) |
| 26 | }) |
| 27 | } |
| 28 | |