mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-16 23:27:17 +02:00
Use std::filesystem::path
in more places (#10657)
Progress on #9205 Co-Authored-By: John Ericson <John.Ericson@Obsidian.Systems> * Get rid of `PathNG`, just use `std::filesystem::path`
This commit is contained in:
parent
9ae6455b0e
commit
fcbc36cf78
13 changed files with 104 additions and 82 deletions
|
@ -108,7 +108,7 @@ struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfi
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string name() override { return "Experimental SSH Store with filesytem mounted"; }
|
const std::string name() override { return "Experimental SSH Store with filesystem mounted"; }
|
||||||
|
|
||||||
std::string doc() override
|
std::string doc() override
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,11 +31,11 @@ void SSHMaster::addCommonSSHOpts(Strings & args)
|
||||||
if (!keyFile.empty())
|
if (!keyFile.empty())
|
||||||
args.insert(args.end(), {"-i", keyFile});
|
args.insert(args.end(), {"-i", keyFile});
|
||||||
if (!sshPublicHostKey.empty()) {
|
if (!sshPublicHostKey.empty()) {
|
||||||
Path fileName = (Path) *state->tmpDir + "/host-key";
|
std::filesystem::path fileName = state->tmpDir->path() / "host-key";
|
||||||
auto p = host.rfind("@");
|
auto p = host.rfind("@");
|
||||||
std::string thost = p != std::string::npos ? std::string(host, p + 1) : host;
|
std::string thost = p != std::string::npos ? std::string(host, p + 1) : host;
|
||||||
writeFile(fileName, thost + " " + base64Decode(sshPublicHostKey) + "\n");
|
writeFile(fileName.string(), thost + " " + base64Decode(sshPublicHostKey) + "\n");
|
||||||
args.insert(args.end(), {"-oUserKnownHostsFile=" + fileName});
|
args.insert(args.end(), {"-oUserKnownHostsFile=" + fileName.string()});
|
||||||
}
|
}
|
||||||
if (compress)
|
if (compress)
|
||||||
args.push_back("-C");
|
args.push_back("-C");
|
||||||
|
|
|
@ -1220,8 +1220,8 @@ StorePath LocalStore::addToStoreFromDump(
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<AutoDelete> delTempDir;
|
std::unique_ptr<AutoDelete> delTempDir;
|
||||||
Path tempPath;
|
std::filesystem::path tempPath;
|
||||||
Path tempDir;
|
std::filesystem::path tempDir;
|
||||||
AutoCloseFD tempDirFd;
|
AutoCloseFD tempDirFd;
|
||||||
|
|
||||||
bool methodsMatch = ContentAddressMethod(FileIngestionMethod(dumpMethod)) == hashMethod;
|
bool methodsMatch = ContentAddressMethod(FileIngestionMethod(dumpMethod)) == hashMethod;
|
||||||
|
@ -1237,9 +1237,9 @@ StorePath LocalStore::addToStoreFromDump(
|
||||||
|
|
||||||
std::tie(tempDir, tempDirFd) = createTempDirInStore();
|
std::tie(tempDir, tempDirFd) = createTempDirInStore();
|
||||||
delTempDir = std::make_unique<AutoDelete>(tempDir);
|
delTempDir = std::make_unique<AutoDelete>(tempDir);
|
||||||
tempPath = tempDir + "/x";
|
tempPath = tempDir / "x";
|
||||||
|
|
||||||
restorePath(tempPath, bothSource, dumpMethod);
|
restorePath(tempPath.string(), bothSource, dumpMethod);
|
||||||
|
|
||||||
dumpBuffer.reset();
|
dumpBuffer.reset();
|
||||||
dump = {};
|
dump = {};
|
||||||
|
@ -1252,7 +1252,7 @@ StorePath LocalStore::addToStoreFromDump(
|
||||||
methodsMatch
|
methodsMatch
|
||||||
? dumpHash
|
? dumpHash
|
||||||
: hashPath(
|
: hashPath(
|
||||||
{getFSSourceAccessor(), CanonPath(tempPath)},
|
PosixSourceAccessor::createAtRoot(tempPath),
|
||||||
hashMethod.getFileIngestionMethod(), hashAlgo),
|
hashMethod.getFileIngestionMethod(), hashAlgo),
|
||||||
{
|
{
|
||||||
.others = references,
|
.others = references,
|
||||||
|
@ -1295,7 +1295,7 @@ StorePath LocalStore::addToStoreFromDump(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Move the temporary path we restored above. */
|
/* Move the temporary path we restored above. */
|
||||||
moveFile(tempPath, realPath);
|
moveFile(tempPath.string(), realPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For computing the nar hash. In recursive SHA-256 mode, this
|
/* For computing the nar hash. In recursive SHA-256 mode, this
|
||||||
|
@ -1330,9 +1330,9 @@ StorePath LocalStore::addToStoreFromDump(
|
||||||
|
|
||||||
/* Create a temporary directory in the store that won't be
|
/* Create a temporary directory in the store that won't be
|
||||||
garbage-collected until the returned FD is closed. */
|
garbage-collected until the returned FD is closed. */
|
||||||
std::pair<Path, AutoCloseFD> LocalStore::createTempDirInStore()
|
std::pair<std::filesystem::path, AutoCloseFD> LocalStore::createTempDirInStore()
|
||||||
{
|
{
|
||||||
Path tmpDirFn;
|
std::filesystem::path tmpDirFn;
|
||||||
AutoCloseFD tmpDirFd;
|
AutoCloseFD tmpDirFd;
|
||||||
bool lockedByUs = false;
|
bool lockedByUs = false;
|
||||||
do {
|
do {
|
||||||
|
@ -1345,7 +1345,7 @@ std::pair<Path, AutoCloseFD> LocalStore::createTempDirInStore()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lockedByUs = lockFile(tmpDirFd.get(), ltWrite, true);
|
lockedByUs = lockFile(tmpDirFd.get(), ltWrite, true);
|
||||||
} while (!pathExists(tmpDirFn) || !lockedByUs);
|
} while (!pathExists(tmpDirFn.string()) || !lockedByUs);
|
||||||
return {tmpDirFn, std::move(tmpDirFd)};
|
return {tmpDirFn, std::move(tmpDirFd)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -377,7 +377,7 @@ private:
|
||||||
|
|
||||||
void findRuntimeRoots(Roots & roots, bool censor);
|
void findRuntimeRoots(Roots & roots, bool censor);
|
||||||
|
|
||||||
std::pair<Path, AutoCloseFD> createTempDirInStore();
|
std::pair<std::filesystem::path, AutoCloseFD> createTempDirInStore();
|
||||||
|
|
||||||
typedef std::unordered_set<ino_t> InodeHash;
|
typedef std::unordered_set<ino_t> InodeHash;
|
||||||
|
|
||||||
|
|
|
@ -282,7 +282,7 @@ constexpr std::array<ExperimentalFeatureDetails, numXpFeatures> xpFeatureDetails
|
||||||
.tag = Xp::MountedSSHStore,
|
.tag = Xp::MountedSSHStore,
|
||||||
.name = "mounted-ssh-store",
|
.name = "mounted-ssh-store",
|
||||||
.description = R"(
|
.description = R"(
|
||||||
Allow the use of the [`mounted SSH store`](@docroot@/command-ref/new-cli/nix3-help-stores.html#experimental-ssh-store-with-filesytem-mounted).
|
Allow the use of the [`mounted SSH store`](@docroot@/command-ref/new-cli/nix3-help-stores.html#experimental-ssh-store-with-filesystem-mounted).
|
||||||
)",
|
)",
|
||||||
.trackingUrl = "https://github.com/NixOS/nix/milestone/43",
|
.trackingUrl = "https://github.com/NixOS/nix/milestone/43",
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,9 +13,8 @@ namespace nix {
|
||||||
*
|
*
|
||||||
* @todo drop `NG` suffix and replace the ones in `types.hh`.
|
* @todo drop `NG` suffix and replace the ones in `types.hh`.
|
||||||
*/
|
*/
|
||||||
typedef std::filesystem::path PathNG;
|
typedef std::list<std::filesystem::path> PathsNG;
|
||||||
typedef std::list<Path> PathsNG;
|
typedef std::set<std::filesystem::path> PathSetNG;
|
||||||
typedef std::set<Path> PathSetNG;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop gap until `std::filesystem::path_view` from P1030R6 exists in a
|
* Stop gap until `std::filesystem::path_view` from P1030R6 exists in a
|
||||||
|
@ -23,18 +22,18 @@ typedef std::set<Path> PathSetNG;
|
||||||
*
|
*
|
||||||
* @todo drop `NG` suffix and replace the one in `types.hh`.
|
* @todo drop `NG` suffix and replace the one in `types.hh`.
|
||||||
*/
|
*/
|
||||||
struct PathViewNG : std::basic_string_view<PathNG::value_type>
|
struct PathViewNG : std::basic_string_view<std::filesystem::path::value_type>
|
||||||
{
|
{
|
||||||
using string_view = std::basic_string_view<PathNG::value_type>;
|
using string_view = std::basic_string_view<std::filesystem::path::value_type>;
|
||||||
|
|
||||||
using string_view::string_view;
|
using string_view::string_view;
|
||||||
|
|
||||||
PathViewNG(const PathNG & path)
|
PathViewNG(const std::filesystem::path & path)
|
||||||
: std::basic_string_view<PathNG::value_type>(path.native())
|
: std::basic_string_view<std::filesystem::path::value_type>(path.native())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
PathViewNG(const PathNG::string_type & path)
|
PathViewNG(const std::filesystem::path::string_type & path)
|
||||||
: std::basic_string_view<PathNG::value_type>(path)
|
: std::basic_string_view<std::filesystem::path::value_type>(path)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
const string_view & native() const { return *this; }
|
const string_view & native() const { return *this; }
|
||||||
|
@ -43,10 +42,19 @@ struct PathViewNG : std::basic_string_view<PathNG::value_type>
|
||||||
|
|
||||||
std::string os_string_to_string(PathViewNG::string_view path);
|
std::string os_string_to_string(PathViewNG::string_view path);
|
||||||
|
|
||||||
PathNG::string_type string_to_os_string(std::string_view s);
|
std::filesystem::path::string_type string_to_os_string(std::string_view s);
|
||||||
|
|
||||||
std::optional<PathNG> maybePathNG(PathView path);
|
std::optional<std::filesystem::path> maybePath(PathView path);
|
||||||
|
|
||||||
PathNG pathNG(PathView path);
|
std::filesystem::path pathNG(PathView path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create string literals with the native character width of paths
|
||||||
|
*/
|
||||||
|
#ifndef _WIN32
|
||||||
|
# define PATHNG_LITERAL(s) s
|
||||||
|
#else
|
||||||
|
# define PATHNG_LITERAL(s) L ## s
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,9 +228,9 @@ bool isLink(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::filesystem::directory_entry> readDirectory(const Path & path)
|
std::vector<fs::directory_entry> readDirectory(const Path & path)
|
||||||
{
|
{
|
||||||
std::vector<std::filesystem::directory_entry> entries;
|
std::vector<fs::directory_entry> entries;
|
||||||
entries.reserve(64);
|
entries.reserve(64);
|
||||||
|
|
||||||
for (auto & entry : fs::directory_iterator{path}) {
|
for (auto & entry : fs::directory_iterator{path}) {
|
||||||
|
@ -342,12 +342,12 @@ void syncParent(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void _deletePath(Descriptor parentfd, const Path & path, uint64_t & bytesFreed)
|
static void _deletePath(Descriptor parentfd, const fs::path & path, uint64_t & bytesFreed)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
checkInterrupt();
|
checkInterrupt();
|
||||||
|
|
||||||
std::string name(baseNameOf(path));
|
std::string name(baseNameOf(path.native()));
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (fstatat(parentfd, name.c_str(), &st,
|
if (fstatat(parentfd, name.c_str(), &st,
|
||||||
|
@ -416,9 +416,9 @@ static void _deletePath(Descriptor parentfd, const Path & path, uint64_t & bytes
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _deletePath(const Path & path, uint64_t & bytesFreed)
|
static void _deletePath(const fs::path & path, uint64_t & bytesFreed)
|
||||||
{
|
{
|
||||||
Path dir = dirOf(path);
|
Path dir = dirOf(path.string());
|
||||||
if (dir == "")
|
if (dir == "")
|
||||||
dir = "/";
|
dir = "/";
|
||||||
|
|
||||||
|
@ -432,7 +432,7 @@ static void _deletePath(const Path & path, uint64_t & bytesFreed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void deletePath(const Path & path)
|
void deletePath(const fs::path & path)
|
||||||
{
|
{
|
||||||
uint64_t dummy;
|
uint64_t dummy;
|
||||||
deletePath(path, dummy);
|
deletePath(path, dummy);
|
||||||
|
@ -466,7 +466,7 @@ Paths createDirs(const Path & path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void deletePath(const Path & path, uint64_t & bytesFreed)
|
void deletePath(const fs::path & path, uint64_t & bytesFreed)
|
||||||
{
|
{
|
||||||
//Activity act(*logger, lvlDebug, "recursively deleting path '%1%'", path);
|
//Activity act(*logger, lvlDebug, "recursively deleting path '%1%'", path);
|
||||||
bytesFreed = 0;
|
bytesFreed = 0;
|
||||||
|
@ -478,7 +478,7 @@ void deletePath(const Path & path, uint64_t & bytesFreed)
|
||||||
|
|
||||||
AutoDelete::AutoDelete() : del{false} {}
|
AutoDelete::AutoDelete() : del{false} {}
|
||||||
|
|
||||||
AutoDelete::AutoDelete(const std::string & p, bool recursive) : path(p)
|
AutoDelete::AutoDelete(const fs::path & p, bool recursive) : _path(p)
|
||||||
{
|
{
|
||||||
del = true;
|
del = true;
|
||||||
this->recursive = recursive;
|
this->recursive = recursive;
|
||||||
|
@ -489,10 +489,9 @@ AutoDelete::~AutoDelete()
|
||||||
try {
|
try {
|
||||||
if (del) {
|
if (del) {
|
||||||
if (recursive)
|
if (recursive)
|
||||||
deletePath(path);
|
deletePath(_path);
|
||||||
else {
|
else {
|
||||||
if (remove(path.c_str()) == -1)
|
fs::remove(_path);
|
||||||
throw SysError("cannot unlink '%1%'", path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -505,8 +504,8 @@ void AutoDelete::cancel()
|
||||||
del = false;
|
del = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoDelete::reset(const Path & p, bool recursive) {
|
void AutoDelete::reset(const fs::path & p, bool recursive) {
|
||||||
path = p;
|
_path = p;
|
||||||
this->recursive = recursive;
|
this->recursive = recursive;
|
||||||
del = true;
|
del = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "error.hh"
|
#include "error.hh"
|
||||||
#include "logging.hh"
|
#include "logging.hh"
|
||||||
#include "file-descriptor.hh"
|
#include "file-descriptor.hh"
|
||||||
|
#include "file-path.hh"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -149,9 +150,9 @@ void syncParent(const Path & path);
|
||||||
* recursively. It's not an error if the path does not exist. The
|
* recursively. It's not an error if the path does not exist. The
|
||||||
* second variant returns the number of bytes and blocks freed.
|
* second variant returns the number of bytes and blocks freed.
|
||||||
*/
|
*/
|
||||||
void deletePath(const Path & path);
|
void deletePath(const std::filesystem::path & path);
|
||||||
|
|
||||||
void deletePath(const 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. Returns the
|
||||||
|
@ -197,17 +198,23 @@ void copyFile(const Path & oldPath, const Path & newPath, bool andDelete);
|
||||||
*/
|
*/
|
||||||
class AutoDelete
|
class AutoDelete
|
||||||
{
|
{
|
||||||
Path path;
|
std::filesystem::path _path;
|
||||||
bool del;
|
bool del;
|
||||||
bool recursive;
|
bool recursive;
|
||||||
public:
|
public:
|
||||||
AutoDelete();
|
AutoDelete();
|
||||||
AutoDelete(const Path & p, bool recursive = true);
|
AutoDelete(const std::filesystem::path & p, bool recursive = true);
|
||||||
~AutoDelete();
|
~AutoDelete();
|
||||||
|
|
||||||
void cancel();
|
void cancel();
|
||||||
void reset(const Path & p, bool recursive = true);
|
|
||||||
operator Path() const { return path; }
|
void reset(const std::filesystem::path & p, bool recursive = true);
|
||||||
operator PathView() const { return path; }
|
|
||||||
|
const std::filesystem::path & path() const { return _path; }
|
||||||
|
PathViewNG view() const { return _path; }
|
||||||
|
|
||||||
|
operator const std::filesystem::path & () const { return _path; }
|
||||||
|
operator PathViewNG () const { return _path; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,17 +13,17 @@ std::string os_string_to_string(PathViewNG::string_view path)
|
||||||
return std::string { path };
|
return std::string { path };
|
||||||
}
|
}
|
||||||
|
|
||||||
PathNG::string_type string_to_os_string(std::string_view s)
|
std::filesystem::path::string_type string_to_os_string(std::string_view s)
|
||||||
{
|
{
|
||||||
return std::string { s };
|
return std::string { s };
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<PathNG> maybePathNG(PathView path)
|
std::optional<std::filesystem::path> maybePath(PathView path)
|
||||||
{
|
{
|
||||||
return { path };
|
return { path };
|
||||||
}
|
}
|
||||||
|
|
||||||
PathNG pathNG(PathView path)
|
std::filesystem::path pathNG(PathView path)
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,35 +12,35 @@ namespace nix {
|
||||||
std::string os_string_to_string(PathViewNG::string_view path)
|
std::string os_string_to_string(PathViewNG::string_view path)
|
||||||
{
|
{
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
return converter.to_bytes(PathNG::string_type { path });
|
return converter.to_bytes(std::filesystem::path::string_type { path });
|
||||||
}
|
}
|
||||||
|
|
||||||
PathNG::string_type string_to_os_string(std::string_view s)
|
std::filesystem::path::string_type string_to_os_string(std::string_view s)
|
||||||
{
|
{
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||||
return converter.from_bytes(std::string { s });
|
return converter.from_bytes(std::string { s });
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<PathNG> maybePathNG(PathView path)
|
std::optional<std::filesystem::path> maybePath(PathView path)
|
||||||
{
|
{
|
||||||
if (path.length() >= 3 && (('A' <= path[0] && path[0] <= 'Z') || ('a' <= path[0] && path[0] <= 'z')) && path[1] == ':' && WindowsPathTrait<char>::isPathSep(path[2])) {
|
if (path.length() >= 3 && (('A' <= path[0] && path[0] <= 'Z') || ('a' <= path[0] && path[0] <= 'z')) && path[1] == ':' && WindowsPathTrait<char>::isPathSep(path[2])) {
|
||||||
PathNG::string_type sw = string_to_os_string(
|
std::filesystem::path::string_type sw = string_to_os_string(
|
||||||
std::string { "\\\\?\\" } + path);
|
std::string { "\\\\?\\" } + path);
|
||||||
std::replace(sw.begin(), sw.end(), '/', '\\');
|
std::replace(sw.begin(), sw.end(), '/', '\\');
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
if (path.length() >= 7 && path[0] == '\\' && path[1] == '\\' && (path[2] == '.' || path[2] == '?') && path[3] == '\\' &&
|
if (path.length() >= 7 && path[0] == '\\' && path[1] == '\\' && (path[2] == '.' || path[2] == '?') && path[3] == '\\' &&
|
||||||
('A' <= path[4] && path[4] <= 'Z') && path[5] == ':' && WindowsPathTrait<char>::isPathSep(path[6])) {
|
('A' <= path[4] && path[4] <= 'Z') && path[5] == ':' && WindowsPathTrait<char>::isPathSep(path[6])) {
|
||||||
PathNG::string_type sw = string_to_os_string(path);
|
std::filesystem::path::string_type sw = string_to_os_string(path);
|
||||||
std::replace(sw.begin(), sw.end(), '/', '\\');
|
std::replace(sw.begin(), sw.end(), '/', '\\');
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
return std::optional<PathNG::string_type>();
|
return std::optional<std::filesystem::path::string_type>();
|
||||||
}
|
}
|
||||||
|
|
||||||
PathNG pathNG(PathView path)
|
std::filesystem::path pathNG(PathView path)
|
||||||
{
|
{
|
||||||
std::optional<PathNG::string_type> sw = maybePathNG(path);
|
std::optional<std::filesystem::path::string_type> sw = maybePath(path);
|
||||||
if (!sw) {
|
if (!sw) {
|
||||||
// FIXME why are we not using the regular error handling?
|
// FIXME why are we not using the regular error handling?
|
||||||
std::cerr << "invalid path for WinAPI call ["<<path<<"]"<<std::endl;
|
std::cerr << "invalid path for WinAPI call ["<<path<<"]"<<std::endl;
|
||||||
|
|
|
@ -171,7 +171,7 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
; // obsolete
|
; // obsolete
|
||||||
|
|
||||||
else if (*arg == "--no-out-link" || *arg == "--no-link")
|
else if (*arg == "--no-out-link" || *arg == "--no-link")
|
||||||
outLink = (Path) tmpDir + "/result";
|
outLink = (tmpDir.path() / "result").string();
|
||||||
|
|
||||||
else if (*arg == "--attr" || *arg == "-A")
|
else if (*arg == "--attr" || *arg == "-A")
|
||||||
attrPaths.push_back(getArg(*arg, arg, end));
|
attrPaths.push_back(getArg(*arg, arg, end));
|
||||||
|
@ -504,7 +504,7 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
if (passAsFile.count(var.first)) {
|
if (passAsFile.count(var.first)) {
|
||||||
keepTmp = true;
|
keepTmp = true;
|
||||||
auto fn = ".attr-" + std::to_string(fileNr++);
|
auto fn = ".attr-" + std::to_string(fileNr++);
|
||||||
Path p = (Path) tmpDir + "/" + fn;
|
Path p = (tmpDir.path() / fn).string();
|
||||||
writeFile(p, var.second);
|
writeFile(p, var.second);
|
||||||
env[var.first + "Path"] = p;
|
env[var.first + "Path"] = p;
|
||||||
} else
|
} else
|
||||||
|
@ -536,10 +536,10 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
auto json = structAttrs.value();
|
auto json = structAttrs.value();
|
||||||
structuredAttrsRC = writeStructuredAttrsShell(json);
|
structuredAttrsRC = writeStructuredAttrsShell(json);
|
||||||
|
|
||||||
auto attrsJSON = (Path) tmpDir + "/.attrs.json";
|
auto attrsJSON = (tmpDir.path() / ".attrs.json").string();
|
||||||
writeFile(attrsJSON, json.dump());
|
writeFile(attrsJSON, json.dump());
|
||||||
|
|
||||||
auto attrsSH = (Path) tmpDir + "/.attrs.sh";
|
auto attrsSH = (tmpDir.path() / ".attrs.sh").string();
|
||||||
writeFile(attrsSH, structuredAttrsRC);
|
writeFile(attrsSH, structuredAttrsRC);
|
||||||
|
|
||||||
env["NIX_ATTRS_SH_FILE"] = attrsSH;
|
env["NIX_ATTRS_SH_FILE"] = attrsSH;
|
||||||
|
@ -552,7 +552,7 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
convenience, source $stdenv/setup to setup additional
|
convenience, source $stdenv/setup to setup additional
|
||||||
environment variables and shell functions. Also don't
|
environment variables and shell functions. Also don't
|
||||||
lose the current $PATH directories. */
|
lose the current $PATH directories. */
|
||||||
auto rcfile = (Path) tmpDir + "/rc";
|
auto rcfile = (tmpDir.path() / "rc").string();
|
||||||
std::string rc = fmt(
|
std::string rc = fmt(
|
||||||
R"(_nix_shell_clean_tmpdir() { command rm -rf %1%; }; )"s +
|
R"(_nix_shell_clean_tmpdir() { command rm -rf %1%; }; )"s +
|
||||||
(keepTmp ?
|
(keepTmp ?
|
||||||
|
@ -583,7 +583,7 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
"unset TZ; %6%"
|
"unset TZ; %6%"
|
||||||
"shopt -s execfail;"
|
"shopt -s execfail;"
|
||||||
"%7%",
|
"%7%",
|
||||||
shellEscape(tmpDir),
|
shellEscape(tmpDir.path().string()),
|
||||||
(pure ? "" : "p=$PATH; "),
|
(pure ? "" : "p=$PATH; "),
|
||||||
(pure ? "" : "PATH=$PATH:$p; unset p; "),
|
(pure ? "" : "PATH=$PATH:$p; unset p; "),
|
||||||
shellEscape(dirOf(*shell)),
|
shellEscape(dirOf(*shell)),
|
||||||
|
|
|
@ -336,8 +336,8 @@ struct Common : InstallableCommand, MixProfile
|
||||||
std::string makeRcScript(
|
std::string makeRcScript(
|
||||||
ref<Store> store,
|
ref<Store> store,
|
||||||
const BuildEnvironment & buildEnvironment,
|
const BuildEnvironment & buildEnvironment,
|
||||||
const Path & tmpDir,
|
const std::filesystem::path & tmpDir,
|
||||||
const Path & outputsDir = absPath(".") + "/outputs")
|
const std::filesystem::path & outputsDir = std::filesystem::path { absPath(".") } / "outputs")
|
||||||
{
|
{
|
||||||
// A list of colon-separated environment variables that should be
|
// A list of colon-separated environment variables that should be
|
||||||
// prepended to, rather than overwritten, in order to keep the shell usable.
|
// prepended to, rather than overwritten, in order to keep the shell usable.
|
||||||
|
@ -376,13 +376,19 @@ struct Common : InstallableCommand, MixProfile
|
||||||
StringMap rewrites;
|
StringMap rewrites;
|
||||||
if (buildEnvironment.providesStructuredAttrs()) {
|
if (buildEnvironment.providesStructuredAttrs()) {
|
||||||
for (auto & [outputName, from] : BuildEnvironment::getAssociative(outputs->second)) {
|
for (auto & [outputName, from] : BuildEnvironment::getAssociative(outputs->second)) {
|
||||||
rewrites.insert({from, outputsDir + "/" + outputName});
|
rewrites.insert({
|
||||||
|
from,
|
||||||
|
(outputsDir / outputName).string()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto & outputName : BuildEnvironment::getStrings(outputs->second)) {
|
for (auto & outputName : BuildEnvironment::getStrings(outputs->second)) {
|
||||||
auto from = buildEnvironment.vars.find(outputName);
|
auto from = buildEnvironment.vars.find(outputName);
|
||||||
assert(from != buildEnvironment.vars.end());
|
assert(from != buildEnvironment.vars.end());
|
||||||
rewrites.insert({BuildEnvironment::getString(from->second), outputsDir + "/" + outputName});
|
rewrites.insert({
|
||||||
|
BuildEnvironment::getString(from->second),
|
||||||
|
(outputsDir / outputName).string(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +411,7 @@ struct Common : InstallableCommand, MixProfile
|
||||||
|
|
||||||
if (buildEnvironment.providesStructuredAttrs()) {
|
if (buildEnvironment.providesStructuredAttrs()) {
|
||||||
fixupStructuredAttrs(
|
fixupStructuredAttrs(
|
||||||
"sh",
|
PATHNG_LITERAL("sh"),
|
||||||
"NIX_ATTRS_SH_FILE",
|
"NIX_ATTRS_SH_FILE",
|
||||||
buildEnvironment.getAttrsSH(),
|
buildEnvironment.getAttrsSH(),
|
||||||
rewrites,
|
rewrites,
|
||||||
|
@ -413,7 +419,7 @@ struct Common : InstallableCommand, MixProfile
|
||||||
tmpDir
|
tmpDir
|
||||||
);
|
);
|
||||||
fixupStructuredAttrs(
|
fixupStructuredAttrs(
|
||||||
"json",
|
PATHNG_LITERAL("json"),
|
||||||
"NIX_ATTRS_JSON_FILE",
|
"NIX_ATTRS_JSON_FILE",
|
||||||
buildEnvironment.getAttrsJSON(),
|
buildEnvironment.getAttrsJSON(),
|
||||||
rewrites,
|
rewrites,
|
||||||
|
@ -430,19 +436,21 @@ struct Common : InstallableCommand, MixProfile
|
||||||
* that's accessible from the interactive shell session.
|
* that's accessible from the interactive shell session.
|
||||||
*/
|
*/
|
||||||
void fixupStructuredAttrs(
|
void fixupStructuredAttrs(
|
||||||
const std::string & ext,
|
PathViewNG::string_view ext,
|
||||||
const std::string & envVar,
|
const std::string & envVar,
|
||||||
const std::string & content,
|
const std::string & content,
|
||||||
StringMap & rewrites,
|
StringMap & rewrites,
|
||||||
const BuildEnvironment & buildEnvironment,
|
const BuildEnvironment & buildEnvironment,
|
||||||
const Path & tmpDir)
|
const std::filesystem::path & tmpDir)
|
||||||
{
|
{
|
||||||
auto targetFilePath = tmpDir + "/.attrs." + ext;
|
auto targetFilePath = tmpDir / PATHNG_LITERAL(".attrs.");
|
||||||
writeFile(targetFilePath, content);
|
targetFilePath += ext;
|
||||||
|
|
||||||
|
writeFile(targetFilePath.string(), content);
|
||||||
|
|
||||||
auto fileInBuilderEnv = buildEnvironment.vars.find(envVar);
|
auto fileInBuilderEnv = buildEnvironment.vars.find(envVar);
|
||||||
assert(fileInBuilderEnv != buildEnvironment.vars.end());
|
assert(fileInBuilderEnv != buildEnvironment.vars.end());
|
||||||
rewrites.insert({BuildEnvironment::getString(fileInBuilderEnv->second), targetFilePath});
|
rewrites.insert({BuildEnvironment::getString(fileInBuilderEnv->second), targetFilePath.string()});
|
||||||
}
|
}
|
||||||
|
|
||||||
Strings getDefaultFlakeAttrPaths() override
|
Strings getDefaultFlakeAttrPaths() override
|
||||||
|
@ -578,7 +586,7 @@ struct CmdDevelop : Common, MixEnvironment
|
||||||
|
|
||||||
AutoDelete tmpDir(createTempDir("", "nix-develop"), true);
|
AutoDelete tmpDir(createTempDir("", "nix-develop"), true);
|
||||||
|
|
||||||
auto script = makeRcScript(store, buildEnvironment, (Path) tmpDir);
|
auto script = makeRcScript(store, buildEnvironment, tmpDir);
|
||||||
|
|
||||||
if (verbosity >= lvlDebug)
|
if (verbosity >= lvlDebug)
|
||||||
script += "set -x\n";
|
script += "set -x\n";
|
||||||
|
|
|
@ -87,7 +87,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
||||||
if (!storePath) {
|
if (!storePath) {
|
||||||
|
|
||||||
AutoDelete tmpDir(createTempDir(), true);
|
AutoDelete tmpDir(createTempDir(), true);
|
||||||
Path tmpFile = (Path) tmpDir + "/tmp";
|
std::filesystem::path tmpFile = tmpDir.path() / "tmp";
|
||||||
|
|
||||||
/* Download the file. */
|
/* Download the file. */
|
||||||
{
|
{
|
||||||
|
@ -95,7 +95,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
||||||
if (executable)
|
if (executable)
|
||||||
mode = 0700;
|
mode = 0700;
|
||||||
|
|
||||||
AutoCloseFD fd = toDescriptor(open(tmpFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, mode));
|
AutoCloseFD fd = toDescriptor(open(tmpFile.string().c_str(), O_WRONLY | O_CREAT | O_EXCL, mode));
|
||||||
if (!fd) throw SysError("creating temporary file '%s'", tmpFile);
|
if (!fd) throw SysError("creating temporary file '%s'", tmpFile);
|
||||||
|
|
||||||
FdSink sink(fd.get());
|
FdSink sink(fd.get());
|
||||||
|
@ -109,15 +109,15 @@ std::tuple<StorePath, Hash> prefetchFile(
|
||||||
if (unpack) {
|
if (unpack) {
|
||||||
Activity act(*logger, lvlChatty, actUnknown,
|
Activity act(*logger, lvlChatty, actUnknown,
|
||||||
fmt("unpacking '%s'", url));
|
fmt("unpacking '%s'", url));
|
||||||
Path unpacked = (Path) tmpDir + "/unpacked";
|
auto unpacked = (tmpDir.path() / "unpacked").string();
|
||||||
createDirs(unpacked);
|
createDirs(unpacked);
|
||||||
unpackTarfile(tmpFile, unpacked);
|
unpackTarfile(tmpFile.string(), unpacked);
|
||||||
|
|
||||||
/* If the archive unpacks to a single file/directory, then use
|
/* If the archive unpacks to a single file/directory, then use
|
||||||
that as the top-level. */
|
that as the top-level. */
|
||||||
auto entries = readDirectory(unpacked);
|
auto entries = readDirectory(unpacked);
|
||||||
if (entries.size() == 1)
|
if (entries.size() == 1)
|
||||||
tmpFile = entries[0].path().string();
|
tmpFile = entries[0].path();
|
||||||
else
|
else
|
||||||
tmpFile = unpacked;
|
tmpFile = unpacked;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue