lundi 7 août 2023

How to avoid fs::directory_iterator exceptions

I'm using the following loop to extract names of files and directories from a root path.

for (const auto& entry : fs::directory_iterator(dirToList, fs::directory_options::skip_permission_denied, ec)) {
.
Doing some work
.
}

I've use ec in order to avoid the exception but i get the following error

terminate called after throwing an instance of 'std::experimental::filesystem::v1::__cxx11::filesystem_error'
  what():  filesystem error: status: Too many levels of symbolic links [/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/proc/self/task/92639/fd/4/media/floppy]
Aborted (core dumped)

The above error seems to be due to symbolic link so i used the following to avoid it.

                if(fs::is_symlink(entry, ec)){
                    std::cerr << "Avoiding symlink!" << std::endl;
                    continue;
                }

still same exception.

  1. How to resolve the above issue.
  2. How to avoid all exceptions related to std::filesystem::experimental altogether. I can go with return error approach as I do not want to handle exceptions.

Aucun commentaire:

Enregistrer un commentaire