MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / write_sandbox_entry

Function write_sandbox_entry

atomic-repository/src/repository/remote_cache.rs:254–309  ·  view source on GitHub ↗

Client side of materializing a view into a remote sandbox: write one entry (as [`Repository::materialize_view_entries`] renders it) under `dir`. An existing file at the path is replaced; nothing else is touched. Every path is checked lexically first (plain relative components, no reserved bookkeeping names), and every write's parent again after the filesystem has resolved it, so an entry can neit

(
    dir: &Path,
    path: &str,
    kind: super::ViewEntryKind,
    mode: u32,
    content: &[u8],
)

Source from the content-addressed store, hash-verified

252/// nor re-point the sandbox. Write every entry, then make the cache with
253/// [`Repository::create_remote_sandbox_cache`].
254pub fn write_sandbox_entry(
255 dir: &Path,
256 path: &str,
257 kind: super::ViewEntryKind,
258 mode: u32,
259 content: &[u8],
260) -> Result<(), RepositoryError> {
261 use super::ViewEntryKind;
262 let target = sandbox_entry_path(dir, path)?;
263 match kind {
264 ViewEntryKind::Directory => {
265 sandbox_entry_parent(dir, &target)?;
266 std::fs::create_dir_all(&target)?;
267 }
268 ViewEntryKind::Symlink => {
269 sandbox_entry_parent(dir, &target)?;
270 match std::fs::symlink_metadata(&target) {
271 Ok(_) => std::fs::remove_file(&target)?,
272 Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
273 Err(e) => return Err(e.into()),
274 }
275 #[cfg(unix)]
276 {
277 let link = std::str::from_utf8(content).map_err(|e| {
278 RepositoryError::InvalidOperation {
279 message: format!("symlink {path:?} has a non-UTF-8 target: {e}"),
280 }
281 })?;
282 std::os::unix::fs::symlink(link, &target)?;
283 }
284 #[cfg(not(unix))]
285 std::fs::write(&target, content)?;
286 }
287 ViewEntryKind::File => {
288 sandbox_entry_parent(dir, &target)?;
289 // Never write through a symlink already sitting at the path.
290 if std::fs::symlink_metadata(&target).is_ok_and(|m| m.file_type().is_symlink()) {
291 std::fs::remove_file(&target)?;
292 }
293 std::fs::write(&target, content)?;
294 #[cfg(unix)]
295 {
296 use std::os::unix::fs::PermissionsExt;
297 let mode = if mode & 0o777 == 0 {
298 0o644
299 } else {
300 mode & 0o777
301 };
302 std::fs::set_permissions(&target, std::fs::Permissions::from_mode(mode))?;
303 }
304 #[cfg(not(unix))]
305 let _ = mode;
306 }
307 }
308 Ok(())
309}
310
311/// How a remote sandbox's cache reaches its repository's owner. The

Callers 6

materializeFunction · 0.85
pair_with_hydrationFunction · 0.85
cache_for_viewFunction · 0.85
materialize_prefix_intoFunction · 0.85
atomic_sandboxFunction · 0.85

Calls 5

sandbox_entry_pathFunction · 0.85
sandbox_entry_parentFunction · 0.85
set_permissionsFunction · 0.85
writeFunction · 0.50
kindMethod · 0.45

Tested by 4

pair_with_hydrationFunction · 0.68
cache_for_viewFunction · 0.68
materialize_prefix_intoFunction · 0.68