libstore: make temporary path prefixes optional
This is not the same thing as passing an empty string, because it avoids the `-` separator. Change-Id: I6a6a69646aa76953078a08c606e8f82c9ec03e8e
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace nix {
|
||||
|
||||
Path createTempDir(const Path & prefix, mode_t mode)
|
||||
Path createTempDir(const std::optional<Path> & prefix, mode_t mode)
|
||||
{
|
||||
return createTempSubdir(defaultTempDir(), prefix, mode);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace nix {
|
||||
/**
|
||||
* Create a temporary directory.
|
||||
*/
|
||||
Path createTempDir(const Path & prefix = "nix", mode_t mode = 0755);
|
||||
Path createTempDir(const std::optional<Path> & prefix = "nix", mode_t mode = 0755);
|
||||
|
||||
/**
|
||||
* Create a temporary file, returning a file handle and its path.
|
||||
|
||||
@@ -646,7 +646,7 @@ void AutoDelete::reset(const Path & p, bool recursive) {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
Path createTempSubdir(const Path & parent, const Path & prefix,
|
||||
Path createTempSubdir(const Path & parent, const std::optional<Path> & prefix,
|
||||
mode_t mode)
|
||||
{
|
||||
checkInterrupt();
|
||||
@@ -670,7 +670,7 @@ Path createTempSubdir(const Path & parent, const Path & prefix,
|
||||
throw SysError("creating directory '%1%'", tmpDir);
|
||||
}
|
||||
|
||||
Path makeTempPath(const Path & root, const Path & prefix)
|
||||
Path makeTempPath(const Path & root, const std::optional<Path> & prefix)
|
||||
{
|
||||
static thread_local std::random_device generator{};
|
||||
std::uniform_int_distribution<uint64_t> uniform_dist{};
|
||||
@@ -679,7 +679,11 @@ Path makeTempPath(const Path & root, const Path & prefix)
|
||||
reinterpret_cast<const char *>(entropy),
|
||||
sizeof(entropy)
|
||||
));
|
||||
return fmt("%s%s-%s", root, prefix, unique);
|
||||
if (prefix) {
|
||||
return fmt("%s%s-%s", root, *prefix, unique);
|
||||
} else {
|
||||
return root + unique;
|
||||
}
|
||||
}
|
||||
|
||||
Path makeTempSiblingPath(const Path & path)
|
||||
|
||||
@@ -307,16 +307,16 @@ typedef std::unique_ptr<DIR, DIRDeleter> AutoCloseDir;
|
||||
/**
|
||||
* Create a temporary directory in a given parent directory.
|
||||
*/
|
||||
Path createTempSubdir(const Path & parent, const Path & prefix = "nix",
|
||||
Path createTempSubdir(const Path & parent, const std::optional<Path> & prefix = "nix",
|
||||
mode_t mode = 0755);
|
||||
|
||||
/**
|
||||
* Return temporary path constructed by appending to a root path.
|
||||
*
|
||||
* The constructed path looks like `<root><prefix>-<unique>`. To create a
|
||||
* The constructed path looks like `<root>[<prefix>-]<unique>`. To create a
|
||||
* path nested in a directory, provide a root ending with `/`.
|
||||
*/
|
||||
Path makeTempPath(const Path & root, const Path & prefix = ".tmp");
|
||||
Path makeTempPath(const Path & root, const std::optional<Path> & prefix = ".tmp");
|
||||
|
||||
/**
|
||||
* Return temporary path in the same directory as a given path.
|
||||
|
||||
Reference in New Issue
Block a user