lolcate-rs icon indicating copy to clipboard operation
lolcate-rs copied to clipboard

How to replace mlocate to index the whole root directory(/)?

Open c02y opened this issue 4 years ago • 4 comments
trafficstars

I use mlocate to generate db file for the whole root directory (/) using the following command without sudo (defualt /etc/updatedb.conf)

updatedb --require-visibility 0 -o /tmp/mlocate.db

But when I set "/" in dirs = part in config.toml file, and execute lolcate --update, it lists a lot of

failed to access entry xxxx

and it takes a lot of time like it never stops.

So, how can I generate db like mloate for the whole root directory (/)

c02y avatar Feb 09 '21 19:02 c02y

You would need to run lolcate with elevated privileges, e.g. using sudo.

ngirard avatar Feb 09 '21 21:02 ngirard

I use updatedb --require-visibility 0 -o /tmp/mlocate.db inside script function, and do it a lot, so it is really not convenient to use sudo, that's why I use --require-visibility 0 for updatedb.


UPDATE: When I'm using sudo lolcate --update, it prints:

Config file not found for database default.
Perhaps you forgot to run lolcate --create default ?

I already executed lolcate --create and modifed ~/.config/lolcate/default/config.toml (add "/" in dirs =) before sudo lolcate --update

So I tried sudo lolcate --create and modifed /root/.config/lolcate/default/config.toml (add "/" in dirs =), this step is apparently not the correct design, anyway, after that, I execute sudo lolcate --update, and the result is the same with using lolcate --update, a lot of the following lines are printed:

failed to access entry xxx

Apparently, a lot of other work needs to be done.

Could be please treat this as a feature request, so I can successfully replace mlocate with lolcate to index the whole filesystem?

c02y avatar Feb 09 '21 21:02 c02y

@c02y some entries are unaccessable by design, running as root should dispense with "Permission denied" errors at least.

It would be useful if the developer could provide a way to run --update as a privileged user in order to maintain full listings at ease. Otherwise, one would have to run as root and copy and change permissions of databases and configuration files.

elig0n avatar Feb 17 '21 19:02 elig0n

@c02y Yes I know, just like updatedb has /etc/updatedb.conf file, we can avoid this failed to access entry problem by code design and conf file.

c02y avatar Feb 17 '21 19:02 c02y

Until then, i'm doing it like this: First, run these commands to set up the databases

lolcate --create --db myrootdb
sudo lolcate --create

then you can use this script to update it

#!/bin/bash 

# copy the local configs for your DB into /root/...
# (-T prevents the files to be copied to /root/.config/lolcate/default/myrootdb/config.toml, we want them directly at /default/config.toml)
sudo cp -T ~/.config/lolcate/myrootdb/ -r /root/.config/lolcate/default/
# update roots default DB and copy the db file back to our local directory
sudo lolcate --update && sudo cp /root/.local/share/lolcate/default/db.lz4  ~/.local/share/lolcate/myrootdb/db.lz4

You can then put this script in the sudo crontab -e * */8 * * * /home/yourname/scripts/updateRootLolcateDB.sh or something to update the db every 8 hours

Lxtharia avatar May 28 '23 10:05 Lxtharia

I already replaced locate/mlocate with fd long time ago, never need to generate or update a db file, it is always real-in-time.

c02y avatar May 28 '23 11:05 c02y

Great if it works for you! I just like having a database for faster search, so i just wanted to share my solution to the original issue :> (Even if it's from 2 years ago lol)

Lxtharia avatar May 28 '23 11:05 Lxtharia

It is very fast, almost instantly every time, no need to worry if db file is outdated anymore, you can try it, highly recommended.

Although crontab solution is working automatically, but still every 8 hours, it is unable to track the new added/deleted files seconds ago, this strategy is no different from the mlocate updatedb service/timer

c02y avatar May 28 '23 11:05 c02y