2016-06-27 01:53:10 +02:00
|
|
|
#include "LocalStateDir.h"
|
|
|
|
#include <cpp-utils/system/homedir.h>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
namespace cryfs {
|
2017-09-28 08:41:08 +02:00
|
|
|
namespace {
|
|
|
|
// TODO constexpr?
|
|
|
|
bf::path& appDir() {
|
|
|
|
static bf::path singleton = cpputils::system::HomeDirectory::get() / ".cryfs";
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-27 01:53:10 +02:00
|
|
|
bf::path LocalStateDir::forFilesystemId(const CryConfig::FilesystemID &filesystemId) {
|
2017-09-28 08:41:08 +02:00
|
|
|
_createDirIfNotExists(appDir());
|
|
|
|
bf::path filesystems_dir = appDir() / "filesystems";
|
2016-06-27 01:53:10 +02:00
|
|
|
_createDirIfNotExists(filesystems_dir);
|
|
|
|
bf::path this_filesystem_dir = filesystems_dir / filesystemId.ToString();
|
|
|
|
_createDirIfNotExists(this_filesystem_dir);
|
|
|
|
return this_filesystem_dir;
|
|
|
|
}
|
|
|
|
|
2017-09-28 08:41:08 +02:00
|
|
|
bf::path LocalStateDir::forMapFromBasedirToConfigFiles() {
|
|
|
|
bf::path result = appDir() / "map_basedir_initialconfigfile";
|
|
|
|
_createDirIfNotExists(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-06-27 01:53:10 +02:00
|
|
|
void LocalStateDir::_createDirIfNotExists(const bf::path &path) {
|
|
|
|
if (!bf::exists(path)) {
|
2017-09-28 08:41:08 +02:00
|
|
|
bf::create_directories(path);
|
2016-06-27 01:53:10 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-28 08:41:08 +02:00
|
|
|
|
|
|
|
void LocalStateDir::setAppDir(boost::filesystem::path path) {
|
|
|
|
appDir() = std::move(path);
|
|
|
|
}
|
2016-06-27 01:53:10 +02:00
|
|
|
}
|