MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / checked_directory_metadata

Function checked_directory_metadata

crates/openshell-server/src/compute/vm.rs:325–358  ·  view source on GitHub ↗
(
    path: &Path,
    expected_uid: u32,
    label: &str,
)

Source from the content-addressed store, hash-verified

323
324#[cfg(unix)]
325fn checked_directory_metadata(
326 path: &Path,
327 expected_uid: u32,
328 label: &str,
329) -> Result<std::fs::Metadata> {
330 let metadata = std::fs::symlink_metadata(path).map_err(|err| {
331 Error::execution(format!(
332 "failed to stat {label} '{}': {err}",
333 path.display()
334 ))
335 })?;
336 let file_type = metadata.file_type();
337 if file_type.is_symlink() {
338 return Err(Error::execution(format!(
339 "{label} '{}' is a symlink; refusing to use it",
340 path.display()
341 )));
342 }
343 if !file_type.is_dir() {
344 return Err(Error::execution(format!(
345 "{label} '{}' is not a directory",
346 path.display()
347 )));
348 }
349 if metadata.uid() != expected_uid {
350 return Err(Error::execution(format!(
351 "{label} '{}' is owned by uid {} but current euid is {}",
352 path.display(),
353 metadata.uid(),
354 expected_uid
355 )));
356 }
357 Ok(metadata)
358}
359
360#[cfg(unix)]
361fn remove_stale_socket(socket_path: &Path, expected_uid: u32) -> Result<()> {

Callers 2

prepare_vm_state_dirFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected