mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
ln: Adapt to modified backup mode determination
This commit is contained in:
parent
3a0164310a
commit
2db1ec99f1
1 changed files with 28 additions and 42 deletions
|
@ -22,6 +22,7 @@ use std::os::unix::fs::symlink;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::os::windows::fs::{symlink_dir, symlink_file};
|
use std::os::windows::fs::{symlink_dir, symlink_file};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use uucore::backup_control::{self, BackupMode};
|
||||||
use uucore::fs::{canonicalize, CanonicalizeMode};
|
use uucore::fs::{canonicalize, CanonicalizeMode};
|
||||||
|
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
@ -43,14 +44,6 @@ pub enum OverwriteMode {
|
||||||
Force,
|
Force,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
||||||
pub enum BackupMode {
|
|
||||||
NoBackup,
|
|
||||||
SimpleBackup,
|
|
||||||
NumberedBackup,
|
|
||||||
ExistingBackup,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_usage() -> String {
|
fn get_usage() -> String {
|
||||||
format!(
|
format!(
|
||||||
"{0} [OPTION]... [-T] TARGET LINK_NAME (1st form)
|
"{0} [OPTION]... [-T] TARGET LINK_NAME (1st form)
|
||||||
|
@ -78,7 +71,7 @@ fn get_long_usage() -> String {
|
||||||
static ABOUT: &str = "change file owner and group";
|
static ABOUT: &str = "change file owner and group";
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const B: &str = "b";
|
pub const BACKUP_NO_ARG: &str = "b";
|
||||||
pub const BACKUP: &str = "backup";
|
pub const BACKUP: &str = "backup";
|
||||||
pub const FORCE: &str = "force";
|
pub const FORCE: &str = "force";
|
||||||
pub const INTERACTIVE: &str = "interactive";
|
pub const INTERACTIVE: &str = "interactive";
|
||||||
|
@ -99,7 +92,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let matches = uu_app()
|
let matches = uu_app()
|
||||||
.usage(&usage[..])
|
.usage(&usage[..])
|
||||||
.after_help(&long_usage[..])
|
.after_help(&*format!(
|
||||||
|
"{}\n{}",
|
||||||
|
long_usage,
|
||||||
|
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||||
|
))
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
|
|
||||||
/* the list of files */
|
/* the list of files */
|
||||||
|
@ -118,33 +115,25 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
OverwriteMode::NoClobber
|
OverwriteMode::NoClobber
|
||||||
};
|
};
|
||||||
|
|
||||||
let backup_mode = if matches.is_present(options::B) {
|
let backup_mode = backup_control::determine_backup_mode(
|
||||||
BackupMode::ExistingBackup
|
matches.is_present(options::BACKUP_NO_ARG),
|
||||||
} else if matches.is_present(options::BACKUP) {
|
matches.is_present(options::BACKUP),
|
||||||
match matches.value_of(options::BACKUP) {
|
matches.value_of(options::BACKUP),
|
||||||
None => BackupMode::ExistingBackup,
|
);
|
||||||
Some(mode) => match mode {
|
let backup_mode = match backup_mode {
|
||||||
"simple" | "never" => BackupMode::SimpleBackup,
|
Err(err) => {
|
||||||
"numbered" | "t" => BackupMode::NumberedBackup,
|
show_usage_error!("{}", err);
|
||||||
"existing" | "nil" => BackupMode::ExistingBackup,
|
return 1;
|
||||||
"none" | "off" => BackupMode::NoBackup,
|
|
||||||
_ => panic!(), // cannot happen as it is managed by clap
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
} else {
|
Ok(mode) => mode,
|
||||||
BackupMode::NoBackup
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let backup_suffix = if matches.is_present(options::SUFFIX) {
|
let backup_suffix = backup_control::determine_backup_suffix(matches.value_of(options::SUFFIX));
|
||||||
matches.value_of(options::SUFFIX).unwrap()
|
|
||||||
} else {
|
|
||||||
"~"
|
|
||||||
};
|
|
||||||
|
|
||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
overwrite: overwrite_mode,
|
overwrite: overwrite_mode,
|
||||||
backup: backup_mode,
|
backup: backup_mode,
|
||||||
suffix: backup_suffix.to_string(),
|
suffix: backup_suffix,
|
||||||
symbolic: matches.is_present(options::SYMBOLIC),
|
symbolic: matches.is_present(options::SYMBOLIC),
|
||||||
relative: matches.is_present(options::RELATIVE),
|
relative: matches.is_present(options::RELATIVE),
|
||||||
target_dir: matches
|
target_dir: matches
|
||||||
|
@ -162,22 +151,19 @@ pub fn uu_app() -> App<'static, 'static> {
|
||||||
App::new(executable!())
|
App::new(executable!())
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.arg(Arg::with_name(options::B).short(options::B).help(
|
|
||||||
"make a backup of each file that would otherwise be overwritten or \
|
|
||||||
removed",
|
|
||||||
))
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::BACKUP)
|
Arg::with_name(options::BACKUP)
|
||||||
.long(options::BACKUP)
|
.long(options::BACKUP)
|
||||||
.help(
|
.help("make a backup of each existing destination file")
|
||||||
"make a backup of each file that would otherwise be overwritten \
|
|
||||||
or removed",
|
|
||||||
)
|
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_values(&[
|
.require_equals(true)
|
||||||
"simple", "never", "numbered", "t", "existing", "nil", "none", "off",
|
.min_values(0)
|
||||||
])
|
.value_name("CONTROL"),
|
||||||
.value_name("METHOD"),
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(options::BACKUP_NO_ARG)
|
||||||
|
.short(options::BACKUP_NO_ARG)
|
||||||
|
.help("like --backup but does not accept an argument"),
|
||||||
)
|
)
|
||||||
// TODO: opts.arg(
|
// TODO: opts.arg(
|
||||||
// Arg::with_name(("d", "directory", "allow users with appropriate privileges to attempt \
|
// Arg::with_name(("d", "directory", "allow users with appropriate privileges to attempt \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue