1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

install: Make use of 'backup_controls' for '--backup' opts

Use the methods and types offered by the 'backup_controls' module to implement
the logic for backing up files instead of overwriting.
This commit is contained in:
Andreas Hartmann 2021-06-23 16:20:10 +02:00
parent a85adf3c3f
commit 49a9f359bb

View file

@ -17,6 +17,7 @@ use file_diff::diff;
use filetime::{set_file_times, FileTime};
use uucore::entries::{grp2gid, usr2uid};
use uucore::perms::{wrap_chgrp, wrap_chown, Verbosity};
use uucore::backup_control::{self, BackupMode};
use libc::{getegid, geteuid};
use std::fs;
@ -33,6 +34,7 @@ const DEFAULT_STRIP_PROGRAM: &str = "strip";
pub struct Behavior {
main_function: MainFunction,
specified_mode: Option<u32>,
backup_mode: BackupMode,
suffix: String,
owner: String,
group: String,
@ -311,18 +313,17 @@ fn behavior(matches: &ArgMatches) -> Result<Behavior, i32> {
None
};
let backup_suffix = if matches.is_present(OPT_SUFFIX) {
matches.value_of(OPT_SUFFIX).ok_or(1)?
} else {
"~"
};
let target_dir = matches.value_of(OPT_TARGET_DIRECTORY).map(|d| d.to_owned());
Ok(Behavior {
main_function,
specified_mode,
suffix: backup_suffix.to_string(),
backup_mode: backup_control::determine_backup_mode(
matches.is_present(OPT_BACKUP_NO_ARG) || matches.is_present(OPT_BACKUP),
matches.value_of(OPT_BACKUP),
),
suffix: backup_control::determine_backup_suffix(
matches.value_of(OPT_SUFFIX)),
owner: matches.value_of(OPT_OWNER).unwrap_or("").to_string(),
group: matches.value_of(OPT_GROUP).unwrap_or("").to_string(),
verbose: matches.is_present(OPT_VERBOSE),