mirror of
https://github.com/NixOS/nix
synced 2024-09-19 23:03:53 -04:00
std::filesystem::create_directories
for createDirs
The implementation of `nix::createDirs` allows it to be a simple wrapper around `std::filesystem::create_directories` as its return value is not used anywhere.
This commit is contained in:
parent
e1b3716d50
commit
25b0242ca6
|
@ -107,8 +107,8 @@ ReadlineLikeInteracter::Guard ReadlineLikeInteracter::init(detail::ReplCompleter
|
||||||
rl_readline_name = "nix-repl";
|
rl_readline_name = "nix-repl";
|
||||||
try {
|
try {
|
||||||
createDirs(dirOf(historyFile));
|
createDirs(dirOf(historyFile));
|
||||||
} catch (SystemError & e) {
|
} catch (std::filesystem::filesystem_error & e) {
|
||||||
logWarning(e.info());
|
warn(e.what());
|
||||||
}
|
}
|
||||||
#ifndef USE_READLINE
|
#ifndef USE_READLINE
|
||||||
el_hist_size = 1000;
|
el_hist_size = 1000;
|
||||||
|
|
|
@ -413,30 +413,9 @@ void deletePath(const fs::path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Paths createDirs(const Path & path)
|
void createDirs(const Path & path)
|
||||||
{
|
{
|
||||||
Paths created;
|
fs::create_directories(path);
|
||||||
if (path == "/") return created;
|
|
||||||
|
|
||||||
struct stat st;
|
|
||||||
if (STAT(path.c_str(), &st) == -1) {
|
|
||||||
created = createDirs(dirOf(path));
|
|
||||||
if (mkdir(path.c_str()
|
|
||||||
#ifndef _WIN32 // TODO abstract mkdir perms for Windows
|
|
||||||
, 0777
|
|
||||||
#endif
|
|
||||||
) == -1 && errno != EEXIST)
|
|
||||||
throw SysError("creating directory '%1%'", path);
|
|
||||||
st = STAT(path);
|
|
||||||
created.push_back(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (S_ISLNK(st.st_mode) && stat(path.c_str(), &st) == -1)
|
|
||||||
throw SysError("statting symlink '%1%'", path);
|
|
||||||
|
|
||||||
if (!S_ISDIR(st.st_mode)) throw Error("'%1%' is not a directory", path);
|
|
||||||
|
|
||||||
return created;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -148,11 +148,10 @@ void deletePath(const std::filesystem::path & path);
|
||||||
void deletePath(const std::filesystem::path & path, uint64_t & bytesFreed);
|
void deletePath(const std::filesystem::path & path, uint64_t & bytesFreed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a directory and all its parents, if necessary. Returns the
|
* Create a directory and all its parents, if necessary.
|
||||||
* list of created directories, in order of creation.
|
|
||||||
*/
|
*/
|
||||||
Paths createDirs(const Path & path);
|
void createDirs(const Path & path);
|
||||||
inline Paths createDirs(PathView path)
|
inline void createDirs(PathView path)
|
||||||
{
|
{
|
||||||
return createDirs(Path(path));
|
return createDirs(Path(path));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue