fix operating more than 2 file at the same time

This commit is contained in:
Gabriel B Gutierrez 2021-10-14 17:03:39 -03:00
parent 8c2ae1eed1
commit b3192ddc97
3 changed files with 17 additions and 9 deletions

View File

@ -74,7 +74,7 @@ impl Command for Cp {
}
if interactive && !force {
let mut remove_index: Vec<usize> = vec![];
let mut remove: Vec<usize> = vec![];
for (index, file) in sources.iter().enumerate() {
let prompt = format!(
"Are you shure that you want to copy {} to {}?",
@ -90,10 +90,13 @@ impl Command for Cp {
let input = get_confirmation(prompt)?;
if !input {
remove_index.push(index);
remove.push(index);
}
}
for index in remove_index {
remove.reverse();
for index in remove {
sources.remove(index);
}

View File

@ -60,7 +60,7 @@ impl Command for Mv {
}
if interactive && !force {
let mut remove_index: Vec<usize> = vec![];
let mut remove: Vec<usize> = vec![];
for (index, file) in sources.iter().enumerate() {
let prompt = format!(
"Are you shure that you want to move {} to {}?",
@ -76,10 +76,13 @@ impl Command for Mv {
let input = get_confirmation(prompt)?;
if !input {
remove_index.push(index);
remove.push(index);
}
}
for index in remove_index {
remove.reverse();
for index in remove {
sources.remove(index);
}

View File

@ -127,7 +127,7 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result<Value, ShellError> {
let force = call.has_flag("force");
if interactive && !force {
let mut remove_index: Vec<usize> = vec![];
let mut remove: Vec<usize> = vec![];
for (index, file) in targets.iter().enumerate() {
let prompt: String = format!(
"Are you sure that you what to delete {}?",
@ -137,11 +137,13 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result<Value, ShellError> {
let input = get_confirmation(prompt)?;
if !input {
remove_index.push(index);
remove.push(index);
}
}
for index in remove_index {
remove.reverse();
for index in remove {
targets.remove(index);
}