| 43 | } |
| 44 | |
| 45 | func (f *FileSystem) PutIfNotExists(_ context.Context, u *URI, b []byte) error { |
| 46 | path := u.Filepath() |
| 47 | if err := f.checkPath(path); err != nil { |
| 48 | return fileErr(err) |
| 49 | } |
| 50 | file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_EXCL, f.perm) |
| 51 | if err != nil { |
| 52 | return fileErr(err) |
| 53 | } |
| 54 | _, err = io.Copy(file, bytes.NewReader(b)) |
| 55 | if err != nil { |
| 56 | file.Close() |
| 57 | f.Delete(nil, u) |
| 58 | return err |
| 59 | } |
| 60 | return file.Close() |
| 61 | } |
| 62 | |
| 63 | func (f *FileSystem) Delete(_ context.Context, u *URI) error { |
| 64 | return fileErr(os.Remove(u.Filepath())) |