1
1
mirror of http://git.sesse.net/plocate synced 2025-10-06 02:02:45 +02:00
Files
plocate/lib.h

48 lines
1.7 KiB
C
Raw Permalink Normal View History

Add a native updatedb. This incorporates some code from mlocate's updatedb, and thus is compatible with /etc/updatedb.conf, and supports all the pruning options from it. All the code has been heavily modified, e.g. the gnulib dependency has been removed and replaced with STL code (kicking 10k+ lines of code), the bind mount code has been fixed (it was all broken since the switch from /etc/mtab to /proc/self/mountinfo) and everything has been reformatted. Like with mlocate, plocate's updatedb is merging, ie., it can skip readdir() on unchanged directories. (The logic here is also copied pretty verbatim from mlocate.) updatedb reads plocate's native format; there's a new max_version 2 that contains directory timestamps (without it, updatedb will fall back to a full scan). The timestamps increase the database size by only about 1%, which is a good tradeoff when we're getting rid of the entire mlocate database. We liberally use modern features to simplify the implementation; in particular, openat() to avoid race conditions, instead of mlocate's complicated chdir() dance. Unfortunately, the combination of the slightly strange storage order from mlocate, and openat(), means we can need to keep up a bunch of file descriptors open, but they are not an expensive resource these days, and we try to bump the limit ourselves if we are allowed to. We also use O_TMPFILE, to make sure we never leave a half-finished file lying around (mlocate's updatedb tries to catch signals instead). All of this may hinder portability, so we might ease up on the requirements later. We don't use io_uring for updatedb at this point. plocate-build does not write the needed timestamps, so the first upgrade from mlocate to native plocate requires a full rescan. NOTE: The format is _not_ frozen yet, and won't be until actual release.
2020-11-21 18:23:20 +01:00
/* Common functions.
Copyright (C) 2005, 2007 Red Hat, Inc. All rights reserved.
This copyrighted material is made available to anyone wishing to use, modify,
copy, or redistribute it subject to the terms and conditions of the GNU General
Public License v.2.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
Author: Miloslav Trmac <mitr@redhat.com>
plocate modifications: Copyright (C) 2020 Steinar H. Gunderson.
plocate parts and modifications are licensed under the GPLv2 or, at your option,
any later version.
*/
#ifndef LIB_H__
#define LIB_H__
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <sys/types.h>
#include <vector>
/* Compare two path names using the database directory order. This is not
exactly strcmp () order: "a" < "a.b", so "a/z" < "a.b". */
extern int dir_path_cmp(const std::string &a, const std::string &b);
/* Sort LIST using dir_path_cmp () */
extern void string_list_dir_path_sort(std::vector<std::string> *list);
/* Is PATH included in LIST? Update *IDX to move within LIST.
LIST is assumed to be sorted using dir_path_cmp (), successive calls to this
function are assumed to use PATH values increasing in dir_path_cmp (). */
extern bool string_list_contains_dir_path(const std::vector<std::string> *list,
size_t *idx, const std::string &path);
#endif