forked from M-Labs/rust-fatfs
Allow renaming to the same name
This commit is contained in:
parent
8c1dae9f0c
commit
8995a43bc4
@ -302,6 +302,10 @@ impl <'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
|
|||||||
let mut short_name_gen = ShortNameGenerator::new(dst_name);
|
let mut short_name_gen = ShortNameGenerator::new(dst_name);
|
||||||
let r = dst_dir.find_entry(dst_name, None, Some(&mut short_name_gen));
|
let r = dst_dir.find_entry(dst_name, None, Some(&mut short_name_gen));
|
||||||
if r.is_ok() {
|
if r.is_ok() {
|
||||||
|
// check if source and destination entry is the same
|
||||||
|
if e.is_same_entry(&r.unwrap()) {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
return Err(io::Error::new(ErrorKind::AlreadyExists, "destination file already exists"))
|
return Err(io::Error::new(ErrorKind::AlreadyExists, "destination file already exists"))
|
||||||
}
|
}
|
||||||
// free long and short name entries
|
// free long and short name entries
|
||||||
|
@ -666,6 +666,10 @@ impl <'a, T: ReadWriteSeek> DirEntry<'a, T> {
|
|||||||
DirEntryEditor::new(self.data.clone(), self.entry_pos)
|
DirEntryEditor::new(self.data.clone(), self.entry_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_same_entry(&self, other: &DirEntry<T>) -> bool {
|
||||||
|
self.entry_pos == other.entry_pos
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `File` struct for this entry.
|
/// Returns `File` struct for this entry.
|
||||||
///
|
///
|
||||||
/// Panics if this is not a file.
|
/// Panics if this is not a file.
|
||||||
|
@ -276,6 +276,8 @@ fn test_rename_file(fs: FileSystem) {
|
|||||||
let names = entries.iter().map(|r| r.file_name()).collect::<Vec<_>>();
|
let names = entries.iter().map(|r| r.file_name()).collect::<Vec<_>>();
|
||||||
assert_eq!(names, ["long.txt", "short.txt", "very", "very-long-dir-name", "moved-file.txt"]);
|
assert_eq!(names, ["long.txt", "short.txt", "very", "very-long-dir-name", "moved-file.txt"]);
|
||||||
|
|
||||||
|
assert!(root_dir.rename("moved-file.txt", &root_dir, "moved-file.txt").is_ok());
|
||||||
|
|
||||||
let new_stats = fs.stats().unwrap();
|
let new_stats = fs.stats().unwrap();
|
||||||
assert_eq!(new_stats.free_clusters(), stats.free_clusters());
|
assert_eq!(new_stats.free_clusters(), stats.free_clusters());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user