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