Skip to content

find: Implement -amin -cmin -mmin age ranges.#355

Merged
sylvestre merged 14 commits into
uutils:mainfrom
hanbings:implement-221
Jun 1, 2024
Merged

find: Implement -amin -cmin -mmin age ranges.#355
sylvestre merged 14 commits into
uutils:mainfrom
hanbings:implement-221

Conversation

@hanbings

Copy link
Copy Markdown
Collaborator

implement: #221

@codecov

codecov Bot commented Apr 19, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 77.96610% with 13 lines in your changes are missing coverage. Please review.

Project coverage is 59.12%. Comparing base (add14db) to head (6579285).

Files Patch % Lines
src/find/matchers/time.rs 73.07% 3 Missing and 4 partials ⚠️
src/find/matchers/mod.rs 50.00% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
+ Coverage   58.83%   59.12%   +0.28%     
==========================================
  Files          30       30              
  Lines        3855     3914      +59     
  Branches      846      863      +17     
==========================================
+ Hits         2268     2314      +46     
- Misses       1254     1259       +5     
- Partials      333      341       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread src/find/matchers/time.rs Outdated
File::create(temp_dir.path().join(new_file_name)).expect("create temp file");
let new_file = get_dir_entry_for(&temp_dir_path, new_file_name);

// mores test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// mores test
// more test

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Changed in new commit.

@cakebaker cakebaker linked an issue Apr 20, 2024 that may be closed by this pull request
@sylvestre

Copy link
Copy Markdown
Contributor

please add integrations tests in https://github.com/uutils/findutils/blob/main/tests/find_cmd_tests.rs
and please tests with invalid values (like string for numerical values)

@hanbings

hanbings commented Apr 20, 2024

Copy link
Copy Markdown
Collaborator Author

please add integrations tests in https://github.com/uutils/findutils/blob/main/tests/find_cmd_tests.rs and please tests with invalid values (like string for numerical values)

I've added tests for string type numbers.
But I found that it is able to recognize error parameters such as 1%2 and +-321, which is different from the GNU find results.

This has to do with the way the convert_arg_to_comparable_value function recognizes and converts numbers, meaning that this problem occurs with both the a/c/mtime and a/c/mmin arguments.

Should I fix them in a new PR?

$ find . -atime 1%2
find: invalid argument `1%2' to `-atime'
$ find . -amin 1%2
find: invalid argument `1%2' to `-amin'
$ ./target/debug/find . -atime 1%2
$ ./target/debug/find . -amin 1%2
./.git
./.git/objects/b1
./.git/objects/7f
./.git/objects/a8
./target/debug/deps
./target/debug/incremental/find_cmd_tests-8yeq2sf4g2ts
...

Comment thread tests/find_cmd_tests.rs Outdated
"\"-60\"", "\"-120\"", "\"-240\"", "\"-60\"", "\"-120\"", "\"-240\"",
];

for (arg, time) in args.iter().zip(times.iter()) {

@cakebaker cakebaker May 13, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this piece of code doesn't do what you think it does ;-) It doesn't create the Cartesian product of args and times:

for (arg, time) in args.iter().zip(times.iter()) {
    println!("{arg}: {time}");
}

outputs:

-amin: -60
-cmin: -120
-mmin: -240

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I replaced it with a nested loop. : )

Comment thread tests/find_cmd_tests.rs Outdated
.code(0);
}

for (arg, time_string) in args.iter().zip(time_strings.iter()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comment.

Comment thread tests/find_cmd_tests.rs Outdated
Comment on lines +530 to +531
for arg in args.iter() {
for time in times.iter() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling iter() is not necessary here.

Suggested change
for arg in args.iter() {
for time in times.iter() {
for arg in args {
for time in times {

Comment thread tests/find_cmd_tests.rs Outdated
Comment on lines +541 to +542
for arg in args.iter() {
for time_string in time_strings.iter() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for arg in args.iter() {
for time_string in time_strings.iter() {
for arg in args {
for time_string in time_strings {

Comment thread tests/find_cmd_tests.rs Outdated
for arg in args.iter() {
for time_string in time_strings.iter() {
Command::cargo_bin("find")
.expect("the except time should not match")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one:

Suggested change
.expect("the except time should not match")
.expect("the time should not match")

Comment thread src/find/mod.rs Outdated
let args = ["-amin", "-cmin", "-mmin"];
let times = ["-60", "-120", "-240", "+60", "+120", "+240"];

for (arg, time) in args.iter().zip(times.iter()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you need a nested loop to get the expected result because zip doesn't generate the Cartesian product of args and times.

@hanbings

Copy link
Copy Markdown
Collaborator Author

Thanks, the conflict has been resolved and the code modified in new commits.

@sylvestre

Copy link
Copy Markdown
Contributor

it would be nice to work on #360 next
it will be easier to detect improvement / regression wrt the GNU test suite

@sylvestre sylvestre merged commit d7057e0 into uutils:main Jun 1, 2024
@hanbings hanbings deleted the implement-221 branch June 1, 2024 09:41
@hanbings

hanbings commented Jun 1, 2024

Copy link
Copy Markdown
Collaborator Author

it would be nice to work on #360 next it will be easier to detect improvement / regression wrt the GNU test suite

Thanks! I will complete it as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: support -amin -cmin -mmin age ranges

3 participants