1

I have created mlocate database with the contents of a particular folder. I see that the updatedb doesn't include the path pointed by the symbolic links in the database.

How can I include the path pointed by the symbolic links in the database?

Surprisingly: mlocate has a default option -L or --follow that follows trailing symbolic links when checking file existence (default).

What purpose does it serves when updatedb doesn't include symlinks!


References:

2
  • slightly off-topic: I prefer to not have updatedb installed in VMs. Commented Jun 9, 2020 at 10:05
  • @RuiFRibeiro Sorry I don't get your point, I too don't have updatedb installed in VMs. Commented Jun 9, 2020 at 13:00

1 Answer 1

0

Using this implementation of plocate with updatedb in it, one can build a custom version to follow symlinks. I don't know if it answers the question also for mlocate, I only use plocate.

If you are certain there will be no loop in your filesystem, you can simply replace the code

e.is_directory = (de->d_type == DT_DIR);

by

e.is_directory = (de->d_type == DT_DIR) || (de->d_type == DT_LNK); // or even just true

in the file updatedb.cpp.

If you might have loops, here is a solution (maybe not very efficient). Always in updatedb.cpp, declare a global variable vector<char*> explored; just before the function int scan(...). Then, add the following code after the two first tests in that function scan:

char buf[PATH_MAX];
realpath(path.c_str(),buf);
for (auto &e : explored)
  if (strcmp(e,buf) == 0)
    return 0;
explored.push_back(buf);

And just before each return of that function, add an explored.pop_back();.

With similar modifications of the code, one can follow symlinks only when inside certain directories, and/or completely exclude some directories of the database, depending on one's need. It is also quite useful to make the results clickable.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.