aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-02 21:28:41 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-02 21:28:41 +0200
commit8ec77614f63e14d1869734b0d21a646667bbf88b (patch)
treea9227b8a7b22914385f0d0d983ade65f238f6842
parentdea18ff99913349ef0f54b80d45c8dfdc8b31f65 (diff)
Move createTempFile to libutil
-rw-r--r--src/libutil/util.cc11
-rw-r--r--src/libutil/util.hh12
-rw-r--r--src/nix/shell.cc10
3 files changed, 19 insertions, 14 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 5598415f5..75b73fcfa 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -461,6 +461,17 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
}
+std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix)
+{
+ Path tmpl(getEnv("TMPDIR", "/tmp") + "/" + prefix + ".XXXXXX");
+ // Strictly speaking, this is UB, but who cares...
+ AutoCloseFD fd(mkstemp((char *) tmpl.c_str()));
+ if (!fd)
+ throw SysError("creating temporary file '%s'", tmpl);
+ return {std::move(fd), tmpl};
+}
+
+
static Lazy<Path> getHome2([]() {
Path homeDir = getEnv("HOME");
if (homeDir.empty()) {
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index 8bd57d2e4..6c9d7c2eb 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -118,10 +118,6 @@ void deletePath(const Path & path);
void deletePath(const Path & path, unsigned long long & bytesFreed);
-/* Create a temporary directory. */
-Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix",
- bool includePid = true, bool useGlobalCounter = true, mode_t mode = 0755);
-
/* Return $HOME or the user's home directory from /etc/passwd. */
Path getHome();
@@ -199,6 +195,14 @@ public:
};
+/* Create a temporary directory. */
+Path createTempDir(const Path & tmpRoot = "", const Path & prefix = "nix",
+ bool includePid = true, bool useGlobalCounter = true, mode_t mode = 0755);
+
+/* Create a temporary file, returning a file handle and its path. */
+std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix = "nix");
+
+
class Pipe
{
public:
diff --git a/src/nix/shell.cc b/src/nix/shell.cc
index d3ecf8de4..95028f10e 100644
--- a/src/nix/shell.cc
+++ b/src/nix/shell.cc
@@ -166,16 +166,6 @@ struct Common : InstallableCommand
}
};
-std::pair<AutoCloseFD, Path> createTempFile(const Path & prefix = "nix")
-{
- Path tmpl(getEnv("TMPDIR", "/tmp") + "/" + prefix + ".XXXXXX");
- // Strictly speaking, this is UB, but who cares...
- AutoCloseFD fd(mkstemp((char *) tmpl.c_str()));
- if (!fd)
- throw SysError("creating temporary file '%s'", tmpl);
- return {std::move(fd), tmpl};
-}
-
struct CmdDevShell : Common
{