Skip to content

Commit

Permalink
Bug 1358134 - Don't use dirent.h in DBTool to check whether a DB exis…
Browse files Browse the repository at this point in the history
…ts r=franziskus

Differential Revision: https://nss-review.dev.mozaws.net/D326
  • Loading branch information
Tim Taubert committed May 23, 2017
1 parent 1ce713c commit 815c59d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions nss-tool/db/dbtool.cc
Expand Up @@ -7,7 +7,6 @@
#include "scoped_ptrs.h"
#include "util.h"

#include <dirent.h>
#include <iomanip>
#include <iostream>
#include <regex>
Expand Down Expand Up @@ -171,24 +170,24 @@ bool DBTool::PathHasDBFiles(std::string path) {
std::regex certDBPattern("cert.*\\.db");
std::regex keyDBPattern("key.*\\.db");

DIR *dir;
if (!(dir = opendir(path.c_str()))) {
PRDir *dir = PR_OpenDir(path.c_str());
if (!dir) {
std::cerr << "Directory " << path << " could not be accessed!" << std::endl;
return false;
}

struct dirent *ent;
PRDirEntry *ent;
bool dbFileExists = false;
while ((ent = readdir(dir))) {
if (std::regex_match(ent->d_name, certDBPattern) ||
std::regex_match(ent->d_name, keyDBPattern) ||
"secmod.db" == std::string(ent->d_name)) {
while ((ent = PR_ReadDir(dir, PR_SKIP_BOTH))) {
if (std::regex_match(ent->name, certDBPattern) ||
std::regex_match(ent->name, keyDBPattern) ||
"secmod.db" == std::string(ent->name)) {
dbFileExists = true;
break;
}
}

closedir(dir);
(void)PR_CloseDir(dir);
return dbFileExists;
}

Expand Down

0 comments on commit 815c59d

Please sign in to comment.