An implementation of the venerable Unix locate facility, with some updating.
Go to file
Elf M. Sternberg d13a76f08a Make prepare_pattern more Rust-like.
This just removes the layer between `prepare_pattern` and
`prepare_pattern_raw`; the function now always returns the
allocated vector.

Oddly, it wasn't possible to encode this using an Option<> in the
`hunt()` function.  The `usize` of the scan variable meant that we'd
never go below zero legally (and Rust wouldn't let that happen), so
the "if we're at zero we have some special cases to check" had to
remain here.  The C version of this code could say "If this pointer
is below the allocated space" which is, to a Rust developer, hella
weird (you're literally pointed at memory you don't own!).

And despite the allocation, despite the special case checks, this code
is *still* twice as fast as its C implementation.
2022-11-24 12:56:13 -08:00
crates Make prepare_pattern more Rust-like. 2022-11-24 12:56:13 -08:00
docs Add a README and LICENSE file. 2021-06-24 11:59:47 -07:00
src Moved everything around so it's more project-y 2022-11-11 08:31:22 -08:00
.gitignore Moved everything around so it's more project-y 2022-11-11 08:31:22 -08:00
Cargo.toml Moved everything around so it's more project-y 2022-11-11 08:31:22 -08:00
README.md Moved everything around so it's more project-y 2022-11-11 08:31:22 -08:00

README.md

Language: Rust Topic: System Tools Library Status: In Progress Command Line Status: Pending

rlocate

locate is an unix utility for finding files by filename. It runs a scheduled task that updates a simple database file with the list of every file in the system, and provides a tool for querying that database.

locate was first released in 1994, accompanying the release of BSD 4.4 Unix. mlocate is a more modern implementation that improves performance in the scanner by copying the contents of a folder that hasn't changed since the last scan (although it still has to recurse down that folder's subfolders).

rlocate seeks to update these two, and provide better functionality going forward.

Features

Right now, none of this works. The intended feature list is:

  • Can read the following locatedb formats:
    • MLOCATE
  • Provides new locatedb formats:
    • RLOCR01: Directory path prefixes are built by reference, making for a much smaller database.
    • RLOCR02: RLOCR01, but compressed.
  • Dynamic, real-time monitoring of local (not networked) filesystems, with real-time updating. (Currently Linux only; Requires located-server feature flag.)
  • A library for accessing the RLocate database or the RLocate server.
  • A C FFI for that library.

Installation

rlocate is a replacement for mlocate, which is part of the findutils package, and you do not want to damage that. After building, install the client, and updater or server (depending on which you built) into the folder of your choice. If you're using the timed updater, edit your cron table to run it, removing the mlocate entry. If you're using the server, you can run it and it should just work. It may take some time to build an initial database file, however.

Motivation

I can't remember the project that started this. All I recall was that at one time I was very disappointed to learn that there was no way of scanning the mlocate.db file from a library; the only way to access it was to run a process pipe from inside your C or Rust program. The mlocate.db file has a unique group as is readable only by members of that group; it's also owned by root and can only be updated if the updatedb program is run by root.

I wanted something that was both better and had fewer security requirements. This is the result of that project.

It also let me get back into writing Rust, something I haven't done in awhile.

LICENSE

rlocate is Copyright Elf M. Sternberg (c) 2019, and licensed with the Mozilla Public License vers. 2.0. A copy of the license file is included in the root folder.