MCPcopy Create free account
hub / github.com/brimdata/super / PutIfNotExists

Method PutIfNotExists

pkg/storage/file.go:45–61  ·  view source on GitHub ↗
(_ context.Context, u *URI, b []byte)

Source from the content-addressed store, hash-verified

43}
44
45func (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
63func (f *FileSystem) Delete(_ context.Context, u *URI) error {
64 return fileErr(os.Remove(u.Filepath()))

Callers

nothing calls this directly

Calls 7

checkPathMethod · 0.95
DeleteMethod · 0.95
fileErrFunction · 0.85
CloseMethod · 0.65
FilepathMethod · 0.45
CopyMethod · 0.45
NewReaderMethod · 0.45

Tested by

no test coverage detected