1
0
mirror of https://github.com/uutils/coreutils synced 2024-07-01 06:54:36 +00:00

Compare commits

...

13 Commits

Author SHA1 Message Date
hamflx
76242042c0
Merge 8ca5bd596d into 69b603bfe7 2024-06-29 08:18:34 +08:00
Daniel Hofstetter
69b603bfe7
Merge pull request #6503 from CausingBrick/issue-6495
date: fix date get timezone error while set utc time (#6495)
2024-06-28 16:15:56 +02:00
MengshengWu
e4ec608781 date: fix date get timezone error while set utc time (#6495) 2024-06-28 22:01:00 +08:00
Sylvestre Ledru
371ba28db7
Merge pull request #6498 from cakebaker/cargo_expensive_tests_feature
Cargo.toml: add "expensive_tests" feature
2024-06-28 11:27:27 +02:00
Sylvestre Ledru
7d77a3730c
Merge pull request #6502 from Its-Just-Nans/main
build all features on docs.rs
2024-06-28 11:16:41 +02:00
Daniel Hofstetter
4b0090b323
Merge pull request #6499 from sylvestre/b2sum2
hashsum/b2sum: when the checksum file is untagged, detect the size
2024-06-28 10:44:14 +02:00
n4n5
cc8a9f4c1b
build all features on docs.rs 2024-06-28 10:26:23 +02:00
Sylvestre Ledru
0ecc18fb5b hashsum/b2sum: when the checksum file is untagged, detect the size
Should fix tests/cksum/b2sum.sh
2024-06-28 10:15:27 +02:00
Daniel Hofstetter
11e8476456
Merge pull request #6501 from uutils/renovate/num-bigint-0.x-lockfile
chore(deps): update rust crate num-bigint to v0.4.6
2024-06-28 08:22:52 +02:00
renovate[bot]
2f0b37c7f4
chore(deps): update rust crate num-bigint to v0.4.6 2024-06-27 22:36:46 +00:00
Sylvestre Ledru
3b607f1c7c cksum: move the code where needed 2024-06-27 22:51:37 +02:00
Daniel Hofstetter
b0716baeae Cargo.toml: add "expensive_tests" feature 2024-06-26 15:36:41 +02:00
hamflx
8ca5bd596d mv: Make mv command fallback to copy only if the src and dst are on different device 2024-03-23 12:22:52 +01:00
11 changed files with 146 additions and 32 deletions

View File

@ -136,6 +136,7 @@ vmsplice
# * vars/libc
COMFOLLOW
EXDEV
FILENO
FTSENT
HOSTSIZE

6
Cargo.lock generated
View File

@ -1493,9 +1493,9 @@ dependencies = [
[[package]]
name = "num-bigint"
version = "0.4.5"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7"
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
dependencies = [
"num-integer",
"num-traits",
@ -2931,7 +2931,9 @@ dependencies = [
"clap",
"fs_extra",
"indicatif",
"libc",
"uucore",
"windows-sys 0.48.0",
]
[[package]]

View File

@ -21,6 +21,9 @@ edition = "2021"
build = "build.rs"
[package.metadata.docs.rs]
all-features = true
[features]
default = ["feat_common_core"]
## OS feature shortcodes
@ -30,6 +33,7 @@ windows = ["feat_os_windows"]
## project-specific feature shortcodes
nightly = []
test_unimplemented = []
expensive_tests = []
# * only build `uudoc` when `--feature uudoc` is activated
uudoc = ["zip", "dep:uuhelp_parser"]
## features

View File

@ -227,11 +227,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Box::new(iter)
}
DateSource::Human(relative_time) => {
// Get the current DateTime<FixedOffset> for things like "1 year ago"
let current_time = DateTime::<FixedOffset>::from(Local::now());
// double check the result is overflow or not of the current_time + relative_time
// Double check the result is overflow or not of the current_time + relative_time
// it may cause a panic of chrono::datetime::DateTime add
match current_time.checked_add_signed(relative_time) {
match now.checked_add_signed(relative_time) {
Some(date) => {
let iter = std::iter::once(Ok(date));
Box::new(iter)

View File

@ -207,16 +207,9 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
binary_flag_default
};
let check = matches.get_flag("check");
let tag = matches.get_flag("tag");
let nonames = *matches
.try_get_one("no-names")
.unwrap_or(None)
.unwrap_or(&false);
let status = matches.get_flag("status");
let quiet = matches.get_flag("quiet") || status;
//let strict = matches.get_flag("strict");
let warn = matches.get_flag("warn") && !status;
let zero = matches.get_flag("zero");
let ignore_missing = matches.get_flag("ignore-missing");
if ignore_missing && !check {
@ -224,22 +217,6 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
return Err(ChecksumError::IgnoreNotCheck.into());
}
let opts = Options {
algoname: algo.name,
digest: (algo.create_fn)(),
output_bits: algo.bits,
binary,
//check,
tag,
nonames,
//status,
//quiet,
//strict,
//warn,
zero,
//ignore_missing,
};
if check {
let text_flag = matches.get_flag("text");
let binary_flag = matches.get_flag("binary");
@ -270,6 +247,26 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
);
}
let nonames = *matches
.try_get_one("no-names")
.unwrap_or(None)
.unwrap_or(&false);
let zero = matches.get_flag("zero");
let opts = Options {
algoname: algo.name,
digest: (algo.create_fn)(),
output_bits: algo.bits,
binary,
tag: matches.get_flag("tag"),
nonames,
//status,
//quiet,
//warn,
zero,
//ignore_missing,
};
// Show the hashsum of the input
match matches.get_many::<OsString>(options::FILE) {
Some(files) => hashsum(opts, files.map(|f| f.as_os_str())),

View File

@ -25,6 +25,12 @@ uucore = { workspace = true, features = [
"update-control",
] }
[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_Foundation"] }
[target.'cfg(unix)'.dependencies]
libc = { workspace = true }
[[bin]]
name = "mv"
path = "src/main.rs"

View File

@ -591,7 +591,15 @@ fn rename_with_fallback(
to: &Path,
multi_progress: Option<&MultiProgress>,
) -> io::Result<()> {
if fs::rename(from, to).is_err() {
if let Err(err) = fs::rename(from, to) {
// We will only copy if they're not on the same device, otherwise we'll report an error.
#[cfg(windows)]
const EXDEV: i32 = windows_sys::Win32::Foundation::ERROR_NOT_SAME_DEVICE as _;
#[cfg(unix)]
const EXDEV: i32 = libc::EXDEV as _;
if err.raw_os_error() != Some(EXDEV) {
return Err(err);
}
// Get metadata without following symlinks
let metadata = from.symlink_metadata()?;
let file_type = metadata.file_type();

View File

@ -502,7 +502,6 @@ where
get_expected_checksum(filename_to_check, &caps, &chosen_regex)?;
// If the algo_name is provided, we use it, otherwise we try to detect it
let (algo_name, length) = if is_algo_based_format {
identify_algo_name_and_length(
&caps,
@ -513,7 +512,15 @@ where
.unwrap_or((String::new(), None))
} else if let Some(a) = algo_name_input {
// When a specific algorithm name is input, use it and use the provided bits
(a.to_lowercase(), length_input)
// except when dealing with blake2b, where we will detect the length
if algo_name_input == Some(ALGORITHM_OPTIONS_BLAKE2B) {
// division by 2 converts the length of the Blake2b checksum from hexadecimal
// characters to bytes, as each byte is represented by two hexadecimal characters.
let length = Some(expected_checksum.len() / 2);
(ALGORITHM_OPTIONS_BLAKE2B.to_string(), length)
} else {
(a.to_lowercase(), length_input)
}
} else {
// Default case if no algorithm is specified and non-algo based format is matched
(String::new(), None)

View File

@ -141,6 +141,16 @@ fn test_date_utc() {
}
}
#[test]
fn test_date_utc_issue_6495() {
new_ucmd!()
.arg("-u")
.arg("-d")
.arg("@0")
.succeeds()
.stdout_is("Thu Jan 1 00:00:00 1970\n");
}
#[test]
fn test_date_format_y() {
let scene = TestScenario::new(util_name!());

View File

@ -890,3 +890,39 @@ fn test_star_to_start() {
.succeeds()
.stdout_only("f: OK\n");
}
#[test]
fn test_check_b2sum_strict_check() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("f");
let checksums = [
"2e f\n",
"e4a6a0577479b2b4 f\n",
"cae66941d9efbd404e4d88758ea67670 f\n",
"246c0442cd564aced8145b8b60f1370aa7 f\n",
"0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8 f\n",
"4ded8c5fc8b12f3273f877ca585a44ad6503249a2b345d6d9c0e67d85bcb700db4178c0303e93b8f4ad758b8e2c9fd8b3d0c28e585f1928334bb77d36782e8 f\n",
"786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce f\n",
];
at.write("ck", &checksums.join(""));
let output = "f: OK\n".to_string().repeat(checksums.len());
scene
.ccmd("b2sum")
.arg("-c")
.arg(at.subdir.join("ck"))
.succeeds()
.stdout_only(&output);
scene
.ccmd("b2sum")
.arg("--strict")
.arg("-c")
.arg(at.subdir.join("ck"))
.succeeds()
.stdout_only(&output);
}

View File

@ -1610,6 +1610,51 @@ fn test_acl() {
assert!(compare_xattrs(&file, &file_target));
}
#[test]
#[cfg(windows)]
fn test_move_should_not_fallback_to_copy() {
use std::os::windows::fs::OpenOptionsExt;
let (at, mut ucmd) = at_and_ucmd!();
let locked_file = "a_file_is_locked";
let locked_file_path = at.plus(locked_file);
let file = std::fs::OpenOptions::new()
.create(true)
.write(true)
.share_mode(
uucore::windows_sys::Win32::Storage::FileSystem::FILE_SHARE_READ
| uucore::windows_sys::Win32::Storage::FileSystem::FILE_SHARE_WRITE,
)
.open(locked_file_path);
let target_file = "target_file";
ucmd.arg(locked_file).arg(target_file).fails();
assert!(at.file_exists(locked_file));
assert!(!at.file_exists(target_file));
drop(file);
}
#[test]
#[cfg(unix)]
fn test_move_should_not_fallback_to_copy() {
let (at, mut ucmd) = at_and_ucmd!();
let readonly_dir = "readonly_dir";
let locked_file = "readonly_dir/a_file_is_locked";
at.mkdir(readonly_dir);
at.touch(locked_file);
at.set_mode(readonly_dir, 0o555);
let target_file = "target_file";
ucmd.arg(locked_file).arg(target_file).fails();
assert!(at.file_exists(locked_file));
assert!(!at.file_exists(target_file));
}
// Todo:
// $ at.touch a b