MCPcopy
hub / github.com/kopia/kopia / WriteCacheMarker

Function WriteCacheMarker

internal/cachedir/cachedir.go:30–57  ·  view source on GitHub ↗

WriteCacheMarker writes the CACHEDIR.TAG marker file in a given directory.

(cacheDir string)

Source from the content-addressed store, hash-verified

28
29// WriteCacheMarker writes the CACHEDIR.TAG marker file in a given directory.
30func WriteCacheMarker(cacheDir string) error {
31 if cacheDir == "" {
32 return nil
33 }
34
35 markerFile := filepath.Join(cacheDir, CacheDirMarkerFile)
36
37 st, err := os.Stat(markerFile)
38 if err == nil && st.Size() >= int64(len(cacheDirMarkerContents)) {
39 // ok
40 return nil
41 }
42
43 if err != nil && !os.IsNotExist(err) {
44 return errors.Wrap(err, "unexpected cache marker error")
45 }
46
47 f, err := os.Create(markerFile) //nolint:gosec
48 if err != nil {
49 return errors.Wrap(err, "error creating cache marker")
50 }
51
52 if _, err := f.WriteString(cacheDirMarkerContents); err != nil {
53 return errors.Wrap(err, "unable to write cachedir marker contents")
54 }
55
56 return errors.Wrap(f.Close(), "error closing cache marker file")
57}

Callers 2

PutMethod · 0.92

Calls 4

StatMethod · 0.65
IsNotExistMethod · 0.65
CloseMethod · 0.65
SizeMethod · 0.45

Tested by

no test coverage detected