Skip to content

Commit 0ad66fc

Browse files
committed
Handle no renaming pattern
1 parent 36c9ac4 commit 0ad66fc

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

src/op.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ fn log(op: &OpKind) {
5757
info!("DELETE: {:?}", item_to_pathvec(&op.original));
5858
}
5959
OpKind::Rename(op) => {
60-
info!(
61-
"RENAME: {:?}",
62-
op.iter()
63-
.map(|v| format!("{:?} -> {:?}", v.0, v.1))
64-
.collect::<Vec<String>>()
65-
);
60+
if !op.is_empty() {
61+
info!(
62+
"RENAME: {:?}",
63+
op.iter()
64+
.map(|v| format!("{:?} -> {:?}", v.0, v.1))
65+
.collect::<Vec<String>>()
66+
);
67+
}
6668
}
6769
}
6870
}
@@ -83,14 +85,16 @@ pub fn relog(op: &OpKind, undo: bool) {
8385
info!("{} {:?}", result, item_to_pathvec(&op.original));
8486
}
8587
OpKind::Rename(op) => {
86-
result.push_str("RENAME");
87-
info!(
88-
"{} {:?}",
89-
result,
90-
op.iter()
91-
.map(|v| format!("{:?} -> {:?}", v.0, v.1))
92-
.collect::<Vec<String>>()
93-
);
88+
if !op.is_empty() {
89+
result.push_str("RENAME");
90+
info!(
91+
"{} {:?}",
92+
result,
93+
op.iter()
94+
.map(|v| format!("{:?} -> {:?}", v.0, v.1))
95+
.collect::<Vec<String>>()
96+
);
97+
}
9498
}
9599
}
96100
}

src/run.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,21 +1371,27 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
13711371
.map(ItemBuffer::new)
13721372
.collect();
13731373
execute!(screen, EnterAlternateScreen)?;
1374-
let mut err: Option<FxError> = None;
1375-
if let Err(e) = state.rename_multiple_items(&items) {
1376-
err = Some(e);
1377-
}
1374+
let result = state.rename_multiple_items(&items);
13781375
execute!(screen, EnterAlternateScreen)?;
13791376
hide_cursor();
13801377
state.reset_selection();
13811378
state.reload(state.layout.y)?;
1382-
if let Some(e) = err {
1383-
print_warning(e, state.layout.y);
1384-
} else {
1385-
print_info(
1386-
format!("Renamed {} items.", items.len()),
1387-
state.layout.y,
1388-
);
1379+
match result {
1380+
Err(e) => {
1381+
print_warning(e, state.layout.y);
1382+
}
1383+
Ok(result_len) => {
1384+
let message = {
1385+
match result_len {
1386+
0 => "No item renamed.".to_owned(),
1387+
1 => "1 item renamed.".to_owned(),
1388+
count => {
1389+
format!("{} items renamed.", count)
1390+
}
1391+
}
1392+
};
1393+
print_info(message, state.layout.y);
1394+
}
13891395
}
13901396
continue;
13911397
}

src/state.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ impl State {
12931293
}
12941294

12951295
/// Rename selected items at once.
1296-
pub fn rename_multiple_items(&mut self, items: &[ItemBuffer]) -> Result<(), FxError> {
1296+
pub fn rename_multiple_items(&mut self, items: &[ItemBuffer]) -> Result<usize, FxError> {
12971297
let names: Vec<&str> = items.iter().map(|item| item.file_name.as_str()).collect();
12981298
let mut file = tempfile::NamedTempFile::new()?;
12991299
writeln!(file, "{}", names.join("\n"))?;
@@ -1328,13 +1328,16 @@ impl State {
13281328
for (i, new_name) in new_names.iter().enumerate() {
13291329
let mut to = self.current_dir.clone();
13301330
to.push(new_name);
1331-
std::fs::rename(&items[i].file_path, &to)?;
1332-
result.push((items[i].file_path.clone(), to))
1331+
if &items[i].file_name != new_name {
1332+
std::fs::rename(&items[i].file_path, &to)?;
1333+
result.push((items[i].file_path.clone(), to))
1334+
}
13331335
}
1336+
let len = result.len();
13341337
self.operations.branch();
13351338
self.operations.push(OpKind::Rename(result));
13361339

1337-
Ok(())
1340+
Ok(len)
13381341
}
13391342
}
13401343
}

0 commit comments

Comments
 (0)