Exists reports whether a memory file exists in the requested scope.
(scope memcontract.Scope, filename string)
| 259 | |
| 260 | // Exists reports whether a memory file exists in the requested scope. |
| 261 | func (s *Store) Exists(scope memcontract.Scope, filename string) (bool, error) { |
| 262 | path, err := s.pathFor(scope, filename) |
| 263 | if err != nil { |
| 264 | return false, err |
| 265 | } |
| 266 | |
| 267 | if _, err := os.Stat(path); err != nil { |
| 268 | if errors.Is(err, os.ErrNotExist) { |
| 269 | return false, nil |
| 270 | } |
| 271 | return false, fmt.Errorf("memory: stat %q: %w", path, err) |
| 272 | } |
| 273 | |
| 274 | return true, nil |
| 275 | } |
| 276 | |
| 277 | // Write validates the memory frontmatter and persists the raw file contents atomically. |
| 278 | func (s *Store) Write(scope memcontract.Scope, filename string, content []byte) error { |