mirror of
https://github.com/AGWA/git-crypt.git
synced 2026-01-14 22:13:55 -08:00
Clean up readdir code, add a comment about why we're using readdir
This commit is contained in:
@@ -188,17 +188,22 @@ std::vector<std::string> get_directory_contents (const char* path)
|
|||||||
throw System_error("opendir", path, errno);
|
throw System_error("opendir", path, errno);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
struct dirent* ent = NULL;
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
// Note: readdir is reentrant in new implementations. In old implementations,
|
||||||
while((ent = readdir(dir)) != NULL && errno == 0) {
|
// it might not be, but git-crypt isn't multi-threaded so that's OK.
|
||||||
if (std::strcmp(ent->d_name, ".") && std::strcmp(ent->d_name, ".."))
|
// We don't use readdir_r because it's buggy and deprecated:
|
||||||
|
// https://womble.decadent.org.uk/readdir_r-advisory.html
|
||||||
|
// http://austingroupbugs.net/view.php?id=696
|
||||||
|
// http://man7.org/linux/man-pages/man3/readdir_r.3.html
|
||||||
|
while (struct dirent* ent = readdir(dir)) {
|
||||||
|
if (!(std::strcmp(ent->d_name, ".") == 0 || std::strcmp(ent->d_name, "..") == 0)) {
|
||||||
contents.push_back(ent->d_name);
|
contents.push_back(ent->d_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(errno)
|
if (errno) {
|
||||||
throw System_error("readdir", path, errno);
|
throw System_error("readdir", path, errno);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user