carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux && rootrunner
2
3package rootstate
4
5import (
6 "github.com/carlosframework/platform/internal/safefile"
7 "os"
8)
9
10type faultStore struct {
11 Store
12 step func(string, string, func() error) error
13}
14
15func WithWriteFault(s Store, step func(string, string, func() error) error) Store {
16 return faultStore{Store: s, step: step}
17}
18
19func (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