Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.find() #405

Merged
merged 7 commits into from
Jan 6, 2024
Merged

file.find() #405

merged 7 commits into from
Jan 6, 2024

Conversation

jabbate19
Copy link
Collaborator

What type of PR is this?

/kind documentation
/kind feature
/kind eldritch-function

What this PR does / why we need it:

Adds way to search given directory for file matching criteria.

Please give feedback on current implementation. Imo its kinda rough.

Which issue(s) this PR fixes:

Fixes #66

@jabbate19 jabbate19 requested a review from hulto December 17, 2023 17:07
Copy link

codecov bot commented Dec 17, 2023

Codecov Report

Attention: 69 lines in your changes are missing coverage. Please review.

Comparison is base (4a19ccd) 71.95% compared to head (e9bed88) 71.39%.

Files Patch % Lines
implants/lib/eldritch/src/file/find_impl.rs 0.00% 67 Missing ⚠️
implants/lib/eldritch/src/file.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #405      +/-   ##
==========================================
- Coverage   71.95%   71.39%   -0.56%     
==========================================
  Files         112      113       +1     
  Lines        8729     8800      +71     
==========================================
+ Hits         6281     6283       +2     
- Misses       2339     2408      +69     
  Partials      109      109              

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

Copy link
Collaborator

@hulto hulto left a comment

Choose a reason for hiding this comment

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

Couple changes

implants/lib/eldritch/src/file/find_impl.rs Show resolved Hide resolved
implants/lib/eldritch/src/file/find_impl.rs Outdated Show resolved Hide resolved
}
#[cfg(windows)]
{
if permissions == 0 && metadata.readonly() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be cleaner to switch to a match.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Problem is that for unix I'm making calls to a permissions trait in PermissionsExt, so if we don't do this then the Windows version will try and compile with the use of the unix-only trait and error

Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't it still be bound in the #[cfg(windows)] ?
I'm thinking

#[cfg(windows)]
{
    match permissions {
        0 => {
            if metadata.readonly() { return Ok(false) }
        }
       1 => {
            if !metadata.readonly() { return Ok(false) }
       }
       _ => {
          return anyhow::anyhow!("Windows only supports readonly (0) or not-readonly (1)")
      }
    }
}

}
}
}
if let Some(modified_time) = modified_time {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Outside the scope of this PR but in the future is it possible to add newer than or older than?

Seeing this I realized it'll be be rare files match a specific second.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that was what I was curious about with these. Do we want older/newer to be the default action?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to make the changes in this PR i would:

  • Remove the modified time and created time fields
  • Replace modified time with a modified_before and modified_after option
  • Replace created time with a created_before and created_after option

This would make it possible to time bound your search for things created within a specifir and or modified in a specific range.

implants/lib/eldritch/src/file/find_impl.rs Outdated Show resolved Hide resolved
implants/lib/eldritch/src/file/find_impl.rs Outdated Show resolved Hide resolved
@hulto
Copy link
Collaborator

hulto commented Dec 17, 2023

This looks good to me.
If you want to do the newerthan olderthan I think that would be a great addition but not required.
Nit on match case but NBD if you don't do it.

Copy link
Collaborator

@hulto hulto left a comment

Choose a reason for hiding this comment

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

Works for me.

@jabbate19 jabbate19 merged commit 2e3f27e into main Jan 6, 2024
6 of 8 checks passed
@jabbate19 jabbate19 deleted the file_find branch January 6, 2024 18:17
KCarretto pushed a commit that referenced this pull request Feb 1, 2024
 
file.find() (#405)

* file_find

* Unwraps
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.

Implement file.find
2 participants