Skip to content

Commit

Permalink
fix: check to see if the file exists before attempting to rename
Browse files Browse the repository at this point in the history
In the case of /tmp existing on tmpfs with musl, the prior version of
this would fail with a cross-device link error before bubbling up a not
found error
  • Loading branch information
rtyler authored and ion-elgreco committed May 6, 2024
1 parent e25aed7 commit 7b7aaa5
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions crates/mount/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,19 @@ async fn regular_rename(from: &str, to: &str) -> Result<(), LocalFileSystemError
"Already exists",
)),
})
} else if std::path::Path::new(&from_path).exists() {
std::fs::rename(&from_path, &to_path).map_err(|err| LocalFileSystemError::Generic {
store: STORE_NAME,
source: Box::new(err),
})
} else {
std::fs::rename(&from_path, &to_path).map_err(|err| {
println!("err: {err:?}");
if err.kind() == std::io::ErrorKind::NotFound {
LocalFileSystemError::NotFound {
path: from_path.clone(),
source: Box::new(err),
}
} else {
LocalFileSystemError::Generic {
store: STORE_NAME,
source: Box::new(err),
}
}
})?;
Ok(())
Err(LocalFileSystemError::NotFound {
path: from_path.clone(),
source: Box::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("Could not find {from_path}"),
)),
})
}
})
.await
Expand Down

0 comments on commit 7b7aaa5

Please sign in to comment.