Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental updates like mlocate. #36

Open
freedit-dev opened this issue Aug 31, 2024 · 0 comments
Open

Incremental updates like mlocate. #36

freedit-dev opened this issue Aug 31, 2024 · 0 comments

Comments

@freedit-dev
Copy link

mlocate implements incremental updates compared to its predecessor slocate. Overall, mlocate determines whether to further index the contents of a directory based on whether the directory’s mtime (modification time) or ctime (change time) has changed.

 1   /* "relative" may now become a symlink to somewhere else.  So we use it only
 2      in safe_chdir (). */
 3   entries_mark = obstack_alloc (&scan_dir_state.data_obstack, 0);
 4   dir.path = path;
 5   time_get_ctime (&dir.time, &st);
 6   time_get_mtime (&mtime, &st);
 7   if (time_compare (&dir.time, &mtime) < 0)
 8     dir.time = mtime;
 9   while (old_dir.path != NULL && (cmp = dir_path_cmp (old_dir.path, path)) < 0)
10     {
11       old_dir_skip ();
12       old_dir_next_header ();
13     }
14   did_chdir = false;
15   have_subdir = false;
16   if (old_dir.path != NULL && cmp == 0
17       && time_compare (&dir.time, &old_dir.time) == 0
18       && (dir.time.sec != 0 || dir.time.nsec != 0))
19     {
20       res = copy_old_dir (&dir);
21       if (res != -1)
22     {
23       have_subdir = res;
24       old_dir_next_header ();
25       goto have_dir;
26     }
27     }
28   if (time_is_current (&dir.time))
29     {
30       /* The directory might be changing right now and we can't be sure the
31      timestamp will be changed again if more changes happen very soon, mark
32      the timestamp as invalid to force rescanning the directory next time
33      updatedb is run. */
34       dir.time.sec = 0;
35       dir.time.nsec = 0;
36     }
37   did_chdir = true;
38   if (safe_chdir (cwd_fd, relative, &st) != 0)
39     goto err_chdir;
40   res = scan_cwd (&dir);
41   if (res == -1)
42     goto err_chdir;
43   have_subdir = res;
44  have_dir:
45   write_directory (&dir);
46   if (have_subdir != false)
47     {
48       if (did_chdir == false)
49     {
50       did_chdir = true;
51       if (safe_chdir (cwd_fd, relative, &st) != 0)
52         goto err_entries;
53     }
54       scan_subdirs (&dir, &st);
55     }
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

No branches or pull requests

1 participant