DEVTOOLS: Factor out function to create directories in create_project.

This commit is contained in:
Johannes Schickel 2013-11-07 12:58:35 +01:00 committed by D G Turner
parent 19a20ad71f
commit c00ab00f25
3 changed files with 35 additions and 30 deletions

View file

@ -59,6 +59,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#endif
namespace {
@ -1121,6 +1122,32 @@ FileList listDirectory(const std::string &dir) {
return result;
}
void createDirectory(const std::string &dir) {
#if defined(_WIN32) || defined(WIN32)
if (!CreateDirectory(dir.c_str(), NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS) {
error("Could not create folder \"" + dir + "\"");
}
}
#else
if (mkdir(dir.c_str(), 0777) == -1) {
if (errno == EEXIST) {
// Try to open as a folder (might be a file / symbolic link)
DIR *dirp = opendir(dir.c_str());
if (dirp == NULL) {
error("Could not create folder \"" + dir + "\"");
} else {
// The folder exists, just close the stream and return
closedir(dirp);
}
} else {
error("Could not create folder \"" + dir + "\"");
}
}
#endif
}
/**
* Scans the specified directory against files, which should be included
* in the project files. It will not include files present in the exclude list.