WriteCacheMarker writes the CACHEDIR.TAG marker file in a given directory.
(cacheDir string)
| 28 | |
| 29 | // WriteCacheMarker writes the CACHEDIR.TAG marker file in a given directory. |
| 30 | func 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 | } |
no test coverage detected