# `SiteMaps.Adapters.FileSystem`
[🔗](https://github.com/marcosgz/site_maps_ex/blob/v0.1.0/lib/site_maps/adapters/file_system.ex#L1)

Stores sitemaps in a local directory, including network mounts (NFS, EFS, SMB)
and container volumes.

    adapter: {SiteMaps.Adapters.FileSystem, directory: "/mnt/nfs/sitemaps/acme"}

## Atomic publish

Every file is first written to `<target dir>/.<name>.<random>.tmp`, with
`<name>` cut to its first 100 bytes, in the same directory as the final file,
flushed to disk (`fsync: true`) and then moved into place with a rename. A rename inside one directory is atomic on POSIX file
systems and NFS, so readers on any node see either the old file or the new one,
never a partial file. Leftover `.tmp` files from a crash are never listed;
`list/2` removes the ones whose inode change time is older than `tmp_ttl`, so a
prune run clears them.

When the write meta carries `last_modified`, it becomes the file mtime (whole
seconds) and `read/2` reports it back.

Symbolic links to files and directories are followed by both `read/2` and
`list/2`. The root directory and its missing parents are created on the first
write.

## Options

* `:directory` (`t:String.t/0`) - Required. Root directory, absolute or relative to the current working directory.

* `:file_mode` (`t:non_neg_integer/0`) - Mode of written files. The default value is `420`.

* `:dir_mode` (`t:non_neg_integer/0`) - Mode of directories created by the adapter. The default value is `493`.

* `:fsync` (`t:boolean/0`) - Flush file contents to disk before the rename. The default value is `true`.

* `:tmp_ttl` (`t:non_neg_integer/0`) - Seconds after which a leftover `.tmp` file is removed by `list/2`. The default value is `3600`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
