2018-04-08 00:10:54 +00:00
|
|
|
#include "filesystem.hh"
|
2018-05-13 20:30:24 +00:00
|
|
|
using namespace llvm;
|
2018-04-08 00:10:54 +00:00
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2018-05-14 02:09:26 +00:00
|
|
|
void GetFilesInFolder(std::string folder,
|
|
|
|
bool recursive,
|
|
|
|
bool dir_prefix,
|
|
|
|
const std::function<void(const std::string&)>& handler) {
|
|
|
|
EnsureEndsInSlash(folder);
|
2018-05-13 20:30:24 +00:00
|
|
|
std::error_code ec;
|
|
|
|
if (recursive)
|
|
|
|
for (sys::fs::recursive_directory_iterator I(folder, ec), E; I != E && !ec;
|
|
|
|
I.increment(ec)) {
|
|
|
|
std::string path = I->path(), filename = sys::path::filename(path);
|
|
|
|
if (filename[0] != '.' || filename == ".ccls") {
|
2018-05-14 02:09:26 +00:00
|
|
|
if (!dir_prefix)
|
|
|
|
path = path.substr(folder.size());
|
|
|
|
handler(path);
|
2018-05-13 20:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (sys::fs::directory_iterator I(folder, ec), E; I != E && !ec;
|
|
|
|
I.increment(ec)) {
|
|
|
|
std::string path = I->path(), filename = sys::path::filename(path);
|
|
|
|
if (filename[0] != '.' || filename == ".ccls") {
|
2018-05-14 02:09:26 +00:00
|
|
|
if (!dir_prefix)
|
|
|
|
path = path.substr(folder.size());
|
|
|
|
handler(path);
|
2018-04-08 00:10:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|