Skip to content

implement locate and updatedb#536

Merged
sylvestre merged 18 commits into
uutils:mainfrom
Qelxiros:locate-updatedb
Jun 6, 2026
Merged

implement locate and updatedb#536
sylvestre merged 18 commits into
uutils:mainfrom
Qelxiros:locate-updatedb

Conversation

@Qelxiros

@Qelxiros Qelxiros commented Apr 14, 2025

Copy link
Copy Markdown
Contributor

closes #60

Given that locate has largely been replaced by (m|p)locate, I was unable to find a version of locate packaged for my system (latest Arch Linux), and the packaged version of updatedb does not use the LOCATE02 db format. When running updatedb from source, I encountered errors that were not immediately fixable. As such, this implementation is largely untested, but it's better to have something here to be improved upon.

Comment thread src/locate/main.rs
Comment thread src/locate/mod.rs
@sylvestre

Copy link
Copy Markdown
Contributor

cool, thanks :)
a bunch of tasks are failing

@sylvestre

Copy link
Copy Markdown
Contributor

add please add tests :)

@codecov

codecov Bot commented Apr 16, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.90990% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.05%. Comparing base (1a77a83) to head (91a1836).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/locate/mod.rs 90.64% 24 Missing and 18 partials ⚠️
src/updatedb/mod.rs 97.27% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #536      +/-   ##
==========================================
+ Coverage   91.78%   92.05%   +0.27%     
==========================================
  Files          31       35       +4     
  Lines        6413     7090     +677     
  Branches      338      367      +29     
==========================================
+ Hits         5886     6527     +641     
- Misses        401      420      +19     
- Partials      126      143      +17     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Qelxiros

Qelxiros commented Apr 16, 2025

Copy link
Copy Markdown
Contributor Author

A couple notes:

  • User flags are ignored for updatedb. GNU/BSD/Apple implementations all use a shell script, so they have direct access to su. I'm not sure if there's a better solution from rust, but I left it alone for now.
  • Performance is pretty significantly worse than GNU for updatedb. It might be a problem with find, since updatedb delegates most of the work to it. Locate is about on par with GNU for the one test that I did. I'd love another set of eyes to look for improvements.
  • I'll fix coverage issues tomorrow.
  • Looks like Release / plan is failing due to the Ubuntu 20.04 test runner no longer being available. Is that as simple a fix as updating it to 22.04 or later?

@Qelxiros Qelxiros changed the title implement locate (updatedb coming soon) implement locate and updatedb Apr 16, 2025
Comment thread src/db_tests.rs Outdated
@@ -0,0 +1,79 @@
// Copyright 2017 Google Inc.

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
// Copyright 2017 Google Inc.

Comment thread src/db_tests.rs Outdated
Comment thread Cargo.toml Outdated
Comment thread src/locate/main.rs Outdated
Comment thread src/locate/main.rs
Comment thread Cargo.toml Outdated
Comment thread tests/db_tests.rs Outdated
@Qelxiros Qelxiros requested a review from sylvestre May 12, 2025 00:20
Comment thread src/updatedb/mod.rs Outdated
@@ -0,0 +1,335 @@
// Copyright 2017 Google Inc.

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.

Same, please remove that line and the others

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You asked me in #536 (comment) to add the license header. Should I just be removing the Google line? If so, the most recent commit should be good. If I'm misunderstanding, let me know.

@Qelxiros Qelxiros requested a review from sylvestre May 30, 2025 20:22
@Code7R

Code7R commented Aug 20, 2025

Copy link
Copy Markdown

Is there a reason for the kill switch which blocks operation on Windows?

Proper locate tool may be really interesting in the Windows world, where one would not have to install mingw or cygwin environments.

@Qelxiros

Copy link
Copy Markdown
Contributor Author

@Code7R The current implementation of locate relies on the UNIX-only OsStr::from_bytes. It might be possible to work around this on Windows with OsString::from_wide, but that at least requires a new allocation, and I'm not well-versed enough with Windows encodings to confidently identify how to properly convert from the &[u8] (read in from the db) to &[u16] (required by from_wide). As for updatedb, There's nothing explicitly preventing it from running on Windows, but I can't say with certainty that it doesn't make any UNIX-only assumptions.

@Qelxiros

Copy link
Copy Markdown
Contributor Author

@sylvestre any updates here?

@sylvestre

Copy link
Copy Markdown
Contributor

sorry, let me have a look
i just rebased your pr

sylvestre added 2 commits June 6, 2026 09:28
…yle cleanups

- move invalid_db/old_db/test_data_db from repo root to test_data/db/
- remove add_special_files fixture that wrote into the tracked tree
- replace clap-default unwrap()s and the match_entry CString unwrap
- justify unreachable! branches; drop writeln!(...).unwrap()
- remove #[allow(dead_code)] and unused localuser/netuser Config fields
… building

- locate -e/-E: check the full path with correct follow semantics (a broken
  symlink is non-existent under -L/--follow, existent under -P/--nofollow);
  previously the follow flag was paired with the no-follow probe and basename
  mode checked the wrong path
- locate --regex: report an uncompilable pattern as an error instead of
  silently dropping it (From -> TryFrom, new Error::InvalidRegex)
- updatedb: build the find argv as discrete tokens rather than a formatted
  string that gets re-split on whitespace; an empty prunefs/prunepaths can no
  longer produce an invalid expression (empty '( )' group)
- add unit tests for path_exists and integration tests for the above
@sylvestre sylvestre merged commit c5ff1bb into uutils:main Jun 6, 2026
21 checks passed
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.

locate and updatedb

3 participants