lolautoaccept/src/files.cpp
2022-07-05 23:45:28 +02:00

33 lines
636 B
C++

#include "files.h"
#include <sys/stat.h>
#include <Log.h>
bool mkdirs(const std::string& path) {
size_t offset = 0;
while(offset < path.size()) {
offset = path.find('/', offset+1);
int res = mkdir(path.substr(0, offset).c_str(), S_IRWXU | S_IRWXG); // 770
if(res == -1 && errno != EEXIST) {
// mkdirs failed
return false;
}
}
return true;
}
std::string getHome() {
const char* homevar = getenv("HOME");
if(homevar == nullptr) {
Log::warn << "$HOME is not set! Defaulting to ./";
return "./";
}
return std::string(homevar) + "/";
}
std::string getCache() {
return getHome() + ".cache/lolautoaccept/";
}