(&self, value: &[u8])
| 50 | |
| 51 | #[tracing::instrument(level = "trace", skip(self, value))] |
| 52 | pub async fn put(&self, value: &[u8]) -> io::Result<Hash> { |
| 53 | let h = hash_bytes(value); |
| 54 | let path = self.object_path(&h); |
| 55 | fs::create_dir_all(path.parent().expect("object path must have a parent")).await?; |
| 56 | |
| 57 | // to ensure it doesn't conflict with a concurrent call to put() - suffix with nanosecond timestamp |
| 58 | let ts = std::time::UNIX_EPOCH.elapsed().unwrap().as_nanos(); |
| 59 | let tmp = path.with_extension(format!("tmp{ts}")); |
| 60 | { |
| 61 | let mut f = fs::File::options().write(true).create_new(true).open(&tmp).await?; |
| 62 | f.write_all(value).await?; |
| 63 | f.sync_data().await?; |
| 64 | } |
| 65 | |
| 66 | fs::rename(tmp, path).await?; |
| 67 | |
| 68 | Ok(h) |
| 69 | } |
| 70 | |
| 71 | #[tracing::instrument(level = "trace", skip(self))] |
| 72 | pub async fn prune(&self, key: &Hash) -> anyhow::Result<()> { |
no test coverage detected