R3.1: real paths without \?\ on Windows (dunce); old recent lists read plain
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
1066b41cb0
commit
d0b5aede95
21 files changed
+59
-24
No files matched your search
@@ -10,12 +10,21 @@ const KEEP: usize = 20;
|
||||
|
||||
/// Recently opened paths, newest first.
|
||||
pub fn recent(file: &Path) -> io::Result<Vec<PathBuf>> {
|
||||
match std::fs::read(file) {
|
||||
let listed: Vec<PathBuf> = match std::fs::read(file) {
|
||||
Ok(bytes) => serde_json::from_slice(&bytes)
|
||||
.map_err(|error| io::Error::other(format!("{}: {error}", file.display()))),
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(Vec::new()),
|
||||
Err(error) => Err(error),
|
||||
.map_err(|error| io::Error::other(format!("{}: {error}", file.display())))?,
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => return Ok(Vec::new()),
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
// Older builds wrote `\\?\` paths.
|
||||
let mut list = Vec::with_capacity(listed.len());
|
||||
for path in listed {
|
||||
let plain = dunce::simplified(&path).to_path_buf();
|
||||
if !list.contains(&plain) {
|
||||
list.push(plain);
|
||||
}
|
||||
}
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
/// Takes `root` out of the list.
|
||||
@@ -66,6 +75,13 @@ mod tests {
|
||||
assert_eq!(list[..2], [PathBuf::from("/r/10"), PathBuf::from("/r/24")]);
|
||||
forget(&file, Path::new("/r/10")).expect("forgets");
|
||||
assert_eq!(recent(&file).expect("reads")[0], PathBuf::from("/r/24"));
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let old = [r"\\?\C:\r\old", r"C:\r\old", r"\\?\C:\r\new"];
|
||||
std::fs::write(&file, serde_json::to_vec(&old).expect("json")).expect("writes");
|
||||
let plain = [PathBuf::from(r"C:\r\old"), PathBuf::from(r"C:\r\new")];
|
||||
assert_eq!(recent(&file).expect("reads"), plain);
|
||||
}
|
||||
std::fs::write(&file, "not json").expect("writes");
|
||||
assert!(
|
||||
remember(&file, Path::new("/r/1")).is_err(),
|
||||
|
||||
@@ -183,7 +183,7 @@ pub fn export(
|
||||
|
||||
/// The canonical form of a possibly missing path.
|
||||
fn resolved(path: &Path) -> io::Result<PathBuf> {
|
||||
match std::fs::canonicalize(path) {
|
||||
match dunce::canonicalize(path) {
|
||||
Ok(real) => Ok(real),
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => {
|
||||
let name = path.file_name().ok_or_else(|| {
|
||||
@@ -192,7 +192,7 @@ fn resolved(path: &Path) -> io::Result<PathBuf> {
|
||||
format!("{} has no file name", path.display()),
|
||||
)
|
||||
})?;
|
||||
Ok(std::fs::canonicalize(parent_dir(path))?.join(name))
|
||||
Ok(dunce::canonicalize(parent_dir(path))?.join(name))
|
||||
}
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ impl Sessions {
|
||||
/// The key of an existing file; missing fails loud.
|
||||
fn key(path: &Path) -> io::Result<Key> {
|
||||
Ok(Key {
|
||||
canonical: std::fs::canonicalize(path)?,
|
||||
canonical: dunce::canonicalize(path)?,
|
||||
id: file_id(path)?,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user