51 lines
1.7 KiB
Rust
51 lines
1.7 KiB
Rust
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
//! MLocate
|
|
//!
|
|
//! The readme has the full explanation, but the `locate` suite of
|
|
//! tools present in all Linux distributions is used to locate files
|
|
//! on your storage device. Rather than search the device directly,
|
|
//! `locate` scans a catalog file created during downtime.
|
|
//!
|
|
//! `MLocate` is the most popular implementation of the locate system,
|
|
//! but it has three annoying flaws:
|
|
//!
|
|
//! 1. The archive file isn't very compressed.
|
|
//! 2. The archive file is always an average of 12 hours out of date.
|
|
//! 3. The archive is accessible only through a command line program.
|
|
//!
|
|
//! This program intends to read one of two different formats, the
|
|
//! classic mlocate format, or a new format that exploits a few nifty
|
|
//! tricks to try and make the database file smaller and access
|
|
//! faster.
|
|
|
|
extern crate structview;
|
|
|
|
pub mod database;
|
|
pub mod mlocate_db;
|
|
|
|
use crate::database::LocateDb;
|
|
use crate::mlocate_db::MlHeader;
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use std::fs::File;
|
|
use std::io::{BufRead, BufReader};
|
|
|
|
#[test]
|
|
fn can_read_header() -> Result<(), String> {
|
|
let db = File::open("/var/lib/mlocate/mlocate.db").expect("Unable to open file");
|
|
let mut reader = BufReader::new(db);
|
|
match reader.fill_buf() {
|
|
Ok(buffer) => {
|
|
assert!(MlHeader::is(buffer), "Could not read DB");
|
|
Ok(())
|
|
}
|
|
Err(_) => Err("The header could not be read".to_owned()),
|
|
}
|
|
}
|
|
}
|