(path: &Path, target: &[u8])
| 5049 | } |
| 5050 | |
| 5051 | fn write_atomic_symlink(path: &Path, target: &[u8]) -> Result<(), RepositoryError> { |
| 5052 | let parent = path |
| 5053 | .parent() |
| 5054 | .ok_or_else(|| RepositoryError::InvalidOperation { |
| 5055 | message: format!("cannot replace symlink without parent: {}", path.display()), |
| 5056 | })?; |
| 5057 | fs::create_dir_all(parent)?; |
| 5058 | let staging = tempfile::Builder::new() |
| 5059 | .prefix(".atomic-link-") |
| 5060 | .tempdir_in(parent)?; |
| 5061 | // The staged path is referenced by both cfg arms (symlink on unix, |
| 5062 | // unused-variable suppression on windows), so it must be unconditional. |
| 5063 | let prepared = staging.path().join(BACKUP_VALUE); |
| 5064 | #[cfg(unix)] |
| 5065 | { |
| 5066 | use std::os::unix::ffi::OsStringExt; |
| 5067 | std::os::unix::fs::symlink(std::ffi::OsString::from_vec(target.to_vec()), &prepared)?; |
| 5068 | } |
| 5069 | #[cfg(not(unix))] |
| 5070 | { |
| 5071 | let _ = target; |
| 5072 | let _ = staging; |
| 5073 | // Unreachable on this platform, but the compiler cannot see through |
| 5074 | // the cfg gate — reference the locals so -D warnings is satisfied. |
| 5075 | let _ = &prepared; |
| 5076 | return Err(RepositoryError::InvalidOperation { |
| 5077 | message: "symlink effects are unsupported on this platform".to_string(), |
| 5078 | }); |
| 5079 | } |
| 5080 | #[cfg(unix)] |
| 5081 | { |
| 5082 | remove_filesystem_effect_path(path)?; |
| 5083 | fs::rename(&prepared, path)?; |
| 5084 | sync_directory(parent) |
| 5085 | } |
| 5086 | } |
| 5087 | |
| 5088 | fn write_atomic_gitlink(path: &Path, object_id: &[u8], mode: u32) -> Result<(), RepositoryError> { |
| 5089 | let parent = path |
no test coverage detected