2003-09-11 08:31:29 +00:00
|
|
|
#include <cerrno>
|
|
|
|
#include <algorithm>
|
2003-06-20 14:11:31 +00:00
|
|
|
#include <vector>
|
2014-07-16 14:02:05 +00:00
|
|
|
#include <map>
|
2014-07-17 21:57:17 +00:00
|
|
|
|
2014-07-18 10:54:30 +00:00
|
|
|
#include <strings.h> // for strcasecmp
|
2003-06-20 14:11:31 +00:00
|
|
|
|
2003-06-20 10:40:25 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "archive.hh"
|
|
|
|
#include "util.hh"
|
2018-03-27 16:41:31 +00:00
|
|
|
#include "config.hh"
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
namespace nix {
|
|
|
|
|
2018-03-27 16:41:31 +00:00
|
|
|
struct ArchiveSettings : Config
|
|
|
|
{
|
|
|
|
Setting<bool> useCaseHack{this,
|
|
|
|
#if __APPLE__
|
|
|
|
true,
|
|
|
|
#else
|
|
|
|
false,
|
|
|
|
#endif
|
|
|
|
"use-case-hack",
|
|
|
|
"Whether to enable a Darwin-specific hack for dealing with file name collisions."};
|
2020-11-26 13:26:57 +00:00
|
|
|
Setting<bool> preallocateContents{this, false, "preallocate-contents",
|
2020-09-23 15:39:19 +00:00
|
|
|
"Whether to preallocate files when writing objects with known size."};
|
2018-03-27 16:41:31 +00:00
|
|
|
};
|
2006-09-04 21:06:23 +00:00
|
|
|
|
2018-03-27 16:41:31 +00:00
|
|
|
static ArchiveSettings archiveSettings;
|
|
|
|
|
2020-10-06 11:36:55 +00:00
|
|
|
static GlobalConfig::Register rArchiveSettings(&archiveSettings);
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2017-10-30 18:57:40 +00:00
|
|
|
PathFilter defaultPathFilter = [](const Path &) { return true; };
|
2003-06-23 13:27:59 +00:00
|
|
|
|
|
|
|
|
2021-10-02 21:04:01 +00:00
|
|
|
static void dumpContents(const Path & path, off_t size,
|
2006-11-30 19:19:59 +00:00
|
|
|
Sink & sink)
|
2003-06-20 10:40:25 +00:00
|
|
|
{
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << "contents" << size;
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2016-06-09 14:15:58 +00:00
|
|
|
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
|
2020-04-21 23:07:07 +00:00
|
|
|
if (!fd) throw SysError("opening file '%1%'", path);
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2020-12-02 13:10:56 +00:00
|
|
|
std::vector<char> buf(65536);
|
2009-04-16 12:03:17 +00:00
|
|
|
size_t left = size;
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2006-08-31 15:38:43 +00:00
|
|
|
while (left > 0) {
|
2018-03-22 12:20:55 +00:00
|
|
|
auto n = std::min(left, buf.size());
|
2018-03-01 21:00:58 +00:00
|
|
|
readFull(fd.get(), buf.data(), n);
|
2006-08-31 11:40:39 +00:00
|
|
|
left -= n;
|
2020-12-02 13:10:56 +00:00
|
|
|
sink({buf.data(), n});
|
2003-06-20 10:40:25 +00:00
|
|
|
}
|
|
|
|
|
2003-06-23 13:27:59 +00:00
|
|
|
writePadding(size, sink);
|
2003-06-20 10:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-18 15:56:35 +00:00
|
|
|
static time_t dump(const Path & path, Sink & sink, PathFilter & filter)
|
2003-06-20 10:40:25 +00:00
|
|
|
{
|
2017-08-14 13:28:16 +00:00
|
|
|
checkInterrupt();
|
|
|
|
|
2020-09-23 17:17:28 +00:00
|
|
|
auto st = lstat(path);
|
2022-02-18 15:56:35 +00:00
|
|
|
time_t result = st.st_mtime;
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << "(";
|
2003-06-20 10:40:25 +00:00
|
|
|
|
|
|
|
if (S_ISREG(st.st_mode)) {
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << "type" << "regular";
|
|
|
|
if (st.st_mode & S_IXUSR)
|
|
|
|
sink << "executable" << "";
|
2021-10-02 21:04:01 +00:00
|
|
|
dumpContents(path, st.st_size, sink);
|
2014-07-16 14:02:05 +00:00
|
|
|
}
|
2003-06-20 10:40:25 +00:00
|
|
|
|
|
|
|
else if (S_ISDIR(st.st_mode)) {
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << "type" << "directory";
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2017-07-30 10:26:17 +00:00
|
|
|
/* If we're on a case-insensitive system like macOS, undo
|
2014-07-16 14:02:05 +00:00
|
|
|
the case hack applied by restorePath(). */
|
2022-02-25 15:00:00 +00:00
|
|
|
std::map<std::string, std::string> unhacked;
|
2014-08-01 14:37:47 +00:00
|
|
|
for (auto & i : readDirectory(path))
|
2018-03-27 16:41:31 +00:00
|
|
|
if (archiveSettings.useCaseHack) {
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string name(i.name);
|
2014-08-01 14:37:47 +00:00
|
|
|
size_t pos = i.name.find(caseHackSuffix);
|
2022-02-25 15:00:00 +00:00
|
|
|
if (pos != std::string::npos) {
|
2017-07-30 11:27:57 +00:00
|
|
|
debug(format("removing case hack suffix from '%1%'") % (path + "/" + i.name));
|
2014-07-16 14:02:05 +00:00
|
|
|
name.erase(pos);
|
|
|
|
}
|
2021-12-02 19:56:26 +00:00
|
|
|
if (!unhacked.emplace(name, i.name).second)
|
2020-04-21 23:07:07 +00:00
|
|
|
throw Error("file name collision in between '%1%' and '%2%'",
|
|
|
|
(path + "/" + unhacked[name]),
|
|
|
|
(path + "/" + i.name));
|
2014-07-16 14:02:05 +00:00
|
|
|
} else
|
2021-12-02 19:56:26 +00:00
|
|
|
unhacked.emplace(i.name, i.name);
|
2014-07-16 14:02:05 +00:00
|
|
|
|
|
|
|
for (auto & i : unhacked)
|
|
|
|
if (filter(path + "/" + i.first)) {
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << "entry" << "(" << "name" << i.first << "node";
|
2022-02-18 15:56:35 +00:00
|
|
|
auto tmp_mtime = dump(path + "/" + i.second, sink, filter);
|
|
|
|
if (tmp_mtime > result) {
|
|
|
|
result = tmp_mtime;
|
|
|
|
}
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << ")";
|
2014-07-16 14:02:05 +00:00
|
|
|
}
|
2003-06-20 10:40:25 +00:00
|
|
|
}
|
|
|
|
|
2015-07-19 23:16:16 +00:00
|
|
|
else if (S_ISLNK(st.st_mode))
|
|
|
|
sink << "type" << "symlink" << "target" << readLink(path);
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2020-04-21 23:07:07 +00:00
|
|
|
else throw Error("file '%1%' has an unsupported type", path);
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2015-07-19 23:16:16 +00:00
|
|
|
sink << ")";
|
2022-02-18 15:56:35 +00:00
|
|
|
|
|
|
|
return result;
|
2003-06-20 10:40:25 +00:00
|
|
|
}
|
2003-06-20 14:11:31 +00:00
|
|
|
|
|
|
|
|
2022-02-18 15:56:35 +00:00
|
|
|
time_t dumpPathAndGetMtime(const Path & path, Sink & sink, PathFilter & filter)
|
2003-06-23 13:27:59 +00:00
|
|
|
{
|
2016-02-24 15:52:28 +00:00
|
|
|
sink << narVersionMagic1;
|
2022-02-18 15:56:35 +00:00
|
|
|
return dump(path, sink, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dumpPath(const Path & path, Sink & sink, PathFilter & filter)
|
|
|
|
{
|
|
|
|
dumpPathAndGetMtime(path, sink, filter);
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
void dumpString(std::string_view s, Sink & sink)
|
2016-02-24 15:52:28 +00:00
|
|
|
{
|
|
|
|
sink << narVersionMagic1 << "(" << "type" << "regular" << "contents" << s << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
static SerialisationError badArchive(const std::string & s)
|
2003-06-23 13:27:59 +00:00
|
|
|
{
|
2009-03-22 17:36:43 +00:00
|
|
|
return SerialisationError("bad archive: " + s);
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
#if 0
|
2006-11-30 19:19:59 +00:00
|
|
|
static void skipGeneric(Source & source)
|
2003-06-20 14:11:31 +00:00
|
|
|
{
|
2003-06-23 13:27:59 +00:00
|
|
|
if (readString(source) == "(") {
|
|
|
|
while (readString(source) != ")")
|
|
|
|
skipGeneric(source);
|
|
|
|
}
|
2003-06-20 14:11:31 +00:00
|
|
|
}
|
2014-07-16 14:02:05 +00:00
|
|
|
#endif
|
2003-06-23 13:27:59 +00:00
|
|
|
|
|
|
|
|
2008-12-03 17:30:32 +00:00
|
|
|
static void parseContents(ParseSink & sink, Source & source, const Path & path)
|
2003-06-23 13:27:59 +00:00
|
|
|
{
|
2020-07-30 11:10:49 +00:00
|
|
|
uint64_t size = readLongLong(source);
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2009-03-22 17:36:43 +00:00
|
|
|
sink.preallocateContents(size);
|
|
|
|
|
2020-07-30 11:10:49 +00:00
|
|
|
uint64_t left = size;
|
2020-12-02 13:10:56 +00:00
|
|
|
std::vector<char> buf(65536);
|
2003-06-23 13:27:59 +00:00
|
|
|
|
|
|
|
while (left) {
|
2004-01-15 20:23:55 +00:00
|
|
|
checkInterrupt();
|
2018-03-01 21:00:58 +00:00
|
|
|
auto n = buf.size();
|
2020-07-30 11:10:49 +00:00
|
|
|
if ((uint64_t)n > left) n = left;
|
2018-03-01 21:00:58 +00:00
|
|
|
source(buf.data(), n);
|
2020-12-02 13:10:56 +00:00
|
|
|
sink.receiveContents({buf.data(), n});
|
2003-06-23 13:27:59 +00:00
|
|
|
left -= n;
|
|
|
|
}
|
|
|
|
|
|
|
|
readPadding(size, source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
struct CaseInsensitiveCompare
|
|
|
|
{
|
2022-02-25 15:00:00 +00:00
|
|
|
bool operator() (const std::string & a, const std::string & b) const
|
2014-07-16 14:02:05 +00:00
|
|
|
{
|
|
|
|
return strcasecmp(a.c_str(), b.c_str()) < 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-12-03 17:30:32 +00:00
|
|
|
static void parse(ParseSink & sink, Source & source, const Path & path)
|
2003-06-23 13:27:59 +00:00
|
|
|
{
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string s;
|
2003-06-23 13:27:59 +00:00
|
|
|
|
|
|
|
s = readString(source);
|
|
|
|
if (s != "(") throw badArchive("expected open tag");
|
|
|
|
|
|
|
|
enum { tpUnknown, tpRegular, tpDirectory, tpSymlink } type = tpUnknown;
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
std::map<Path, int, CaseInsensitiveCompare> names;
|
|
|
|
|
2003-06-23 13:27:59 +00:00
|
|
|
while (1) {
|
2004-01-15 20:23:55 +00:00
|
|
|
checkInterrupt();
|
|
|
|
|
2003-06-23 13:27:59 +00:00
|
|
|
s = readString(source);
|
|
|
|
|
|
|
|
if (s == ")") {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (s == "type") {
|
|
|
|
if (type != tpUnknown)
|
|
|
|
throw badArchive("multiple type fields");
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string t = readString(source);
|
2003-06-23 13:27:59 +00:00
|
|
|
|
|
|
|
if (t == "regular") {
|
|
|
|
type = tpRegular;
|
2008-12-03 17:30:32 +00:00
|
|
|
sink.createRegularFile(path);
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (t == "directory") {
|
2008-12-03 17:30:32 +00:00
|
|
|
sink.createDirectory(path);
|
2003-06-23 13:27:59 +00:00
|
|
|
type = tpDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (t == "symlink") {
|
|
|
|
type = tpSymlink;
|
|
|
|
}
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2003-06-23 13:27:59 +00:00
|
|
|
else throw badArchive("unknown file type " + t);
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (s == "contents" && type == tpRegular) {
|
2008-12-03 17:30:32 +00:00
|
|
|
parseContents(sink, source, path);
|
2022-09-22 19:47:43 +00:00
|
|
|
sink.closeRegularFile();
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 11:25:14 +00:00
|
|
|
else if (s == "executable" && type == tpRegular) {
|
2016-02-24 15:52:28 +00:00
|
|
|
auto s = readString(source);
|
|
|
|
if (s != "") throw badArchive("executable marker has non-empty value");
|
2008-12-03 17:30:32 +00:00
|
|
|
sink.isExecutable();
|
2003-07-17 11:25:14 +00:00
|
|
|
}
|
|
|
|
|
2003-06-23 13:27:59 +00:00
|
|
|
else if (s == "entry" && type == tpDirectory) {
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string name, prevName;
|
2014-07-16 14:02:05 +00:00
|
|
|
|
|
|
|
s = readString(source);
|
|
|
|
if (s != "(") throw badArchive("expected open tag");
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
checkInterrupt();
|
|
|
|
|
|
|
|
s = readString(source);
|
|
|
|
|
|
|
|
if (s == ")") {
|
|
|
|
break;
|
|
|
|
} else if (s == "name") {
|
|
|
|
name = readString(source);
|
2022-02-25 15:00:00 +00:00
|
|
|
if (name.empty() || name == "." || name == ".." || name.find('/') != std::string::npos || name.find((char) 0) != std::string::npos)
|
2020-04-21 23:07:07 +00:00
|
|
|
throw Error("NAR contains invalid file name '%1%'", name);
|
2014-07-16 14:30:50 +00:00
|
|
|
if (name <= prevName)
|
|
|
|
throw Error("NAR directory is not sorted");
|
|
|
|
prevName = name;
|
2018-03-27 16:41:31 +00:00
|
|
|
if (archiveSettings.useCaseHack) {
|
2014-07-16 14:02:05 +00:00
|
|
|
auto i = names.find(name);
|
|
|
|
if (i != names.end()) {
|
2017-07-30 11:27:57 +00:00
|
|
|
debug(format("case collision between '%1%' and '%2%'") % i->first % name);
|
2014-07-16 14:02:05 +00:00
|
|
|
name += caseHackSuffix;
|
2015-10-29 12:26:55 +00:00
|
|
|
name += std::to_string(++i->second);
|
2014-07-16 14:02:05 +00:00
|
|
|
} else
|
|
|
|
names[name] = 0;
|
|
|
|
}
|
|
|
|
} else if (s == "node") {
|
2020-06-29 20:45:41 +00:00
|
|
|
if (name.empty()) throw badArchive("entry name missing");
|
2014-07-16 14:02:05 +00:00
|
|
|
parse(sink, source, path + "/" + name);
|
|
|
|
} else
|
|
|
|
throw badArchive("unknown field " + s);
|
|
|
|
}
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (s == "target" && type == tpSymlink) {
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string target = readString(source);
|
2008-12-03 17:30:32 +00:00
|
|
|
sink.createSymlink(path, target);
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
else
|
2003-06-23 13:27:59 +00:00
|
|
|
throw badArchive("unknown field " + s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-03 17:30:32 +00:00
|
|
|
void parseDump(ParseSink & sink, Source & source)
|
2003-06-23 13:27:59 +00:00
|
|
|
{
|
2022-02-25 15:00:00 +00:00
|
|
|
std::string version;
|
2009-03-22 17:36:43 +00:00
|
|
|
try {
|
2018-09-26 10:03:58 +00:00
|
|
|
version = readString(source, narVersionMagic1.size());
|
2009-03-22 17:36:43 +00:00
|
|
|
} catch (SerialisationError & e) {
|
|
|
|
/* This generally means the integer at the start couldn't be
|
|
|
|
decoded. Ignore and throw the exception below. */
|
|
|
|
}
|
2016-02-24 15:52:28 +00:00
|
|
|
if (version != narVersionMagic1)
|
2009-03-22 17:36:43 +00:00
|
|
|
throw badArchive("input doesn't look like a Nix archive");
|
2008-12-03 17:30:32 +00:00
|
|
|
parse(sink, source, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct RestoreSink : ParseSink
|
|
|
|
{
|
|
|
|
Path dstPath;
|
|
|
|
AutoCloseFD fd;
|
|
|
|
|
2020-12-02 13:00:43 +00:00
|
|
|
void createDirectory(const Path & path) override
|
2008-12-03 17:30:32 +00:00
|
|
|
{
|
|
|
|
Path p = dstPath + path;
|
|
|
|
if (mkdir(p.c_str(), 0777) == -1)
|
2020-04-21 23:07:07 +00:00
|
|
|
throw SysError("creating directory '%1%'", p);
|
2008-12-03 17:30:32 +00:00
|
|
|
};
|
|
|
|
|
2020-12-02 13:00:43 +00:00
|
|
|
void createRegularFile(const Path & path) override
|
2008-12-03 17:30:32 +00:00
|
|
|
{
|
|
|
|
Path p = dstPath + path;
|
2016-06-09 14:15:58 +00:00
|
|
|
fd = open(p.c_str(), O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0666);
|
2020-04-21 23:07:07 +00:00
|
|
|
if (!fd) throw SysError("creating file '%1%'", p);
|
2008-12-03 17:30:32 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 19:47:43 +00:00
|
|
|
void closeRegularFile() override
|
|
|
|
{
|
|
|
|
/* Call close explicitly to make sure the error is checked */
|
|
|
|
fd.close();
|
|
|
|
}
|
|
|
|
|
2020-12-02 13:00:43 +00:00
|
|
|
void isExecutable() override
|
2008-12-03 17:30:32 +00:00
|
|
|
{
|
|
|
|
struct stat st;
|
2016-07-11 19:44:44 +00:00
|
|
|
if (fstat(fd.get(), &st) == -1)
|
2008-12-03 17:30:32 +00:00
|
|
|
throw SysError("fstat");
|
2016-07-11 19:44:44 +00:00
|
|
|
if (fchmod(fd.get(), st.st_mode | (S_IXUSR | S_IXGRP | S_IXOTH)) == -1)
|
2008-12-03 17:30:32 +00:00
|
|
|
throw SysError("fchmod");
|
|
|
|
}
|
|
|
|
|
2020-12-02 13:00:43 +00:00
|
|
|
void preallocateContents(uint64_t len) override
|
2009-03-22 17:36:43 +00:00
|
|
|
{
|
2020-09-23 15:39:19 +00:00
|
|
|
if (!archiveSettings.preallocateContents)
|
|
|
|
return;
|
|
|
|
|
2009-03-22 17:36:43 +00:00
|
|
|
#if HAVE_POSIX_FALLOCATE
|
|
|
|
if (len) {
|
2016-07-11 19:44:44 +00:00
|
|
|
errno = posix_fallocate(fd.get(), 0, len);
|
2009-09-30 09:54:29 +00:00
|
|
|
/* Note that EINVAL may indicate that the underlying
|
|
|
|
filesystem doesn't support preallocation (e.g. on
|
|
|
|
OpenSolaris). Since preallocation is just an
|
|
|
|
optimisation, ignore it. */
|
2018-04-04 18:48:50 +00:00
|
|
|
if (errno && errno != EINVAL && errno != EOPNOTSUPP && errno != ENOSYS)
|
2020-04-21 23:07:07 +00:00
|
|
|
throw SysError("preallocating file of %1% bytes", len);
|
2009-03-22 17:36:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-02 13:00:43 +00:00
|
|
|
void receiveContents(std::string_view data) override
|
2008-12-03 17:30:32 +00:00
|
|
|
{
|
2020-12-02 13:00:43 +00:00
|
|
|
writeFull(fd.get(), data);
|
2008-12-03 17:30:32 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 15:00:00 +00:00
|
|
|
void createSymlink(const Path & path, const std::string & target) override
|
2008-12-03 17:30:32 +00:00
|
|
|
{
|
|
|
|
Path p = dstPath + path;
|
2014-02-27 22:17:53 +00:00
|
|
|
nix::createSymlink(target, p);
|
2008-12-03 17:30:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2008-12-03 17:30:32 +00:00
|
|
|
void restorePath(const Path & path, Source & source)
|
|
|
|
{
|
|
|
|
RestoreSink sink;
|
|
|
|
sink.dstPath = path;
|
|
|
|
parseDump(sink, source);
|
2003-06-23 13:27:59 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2018-03-21 21:56:02 +00:00
|
|
|
void copyNAR(Source & source, Sink & sink)
|
|
|
|
{
|
|
|
|
// FIXME: if 'source' is the output of dumpPath() followed by EOF,
|
|
|
|
// we should just forward all data directly without parsing.
|
|
|
|
|
|
|
|
ParseSink parseSink; /* null sink; just parse the NAR */
|
|
|
|
|
2020-08-13 14:47:53 +00:00
|
|
|
TeeSource wrapper { source, sink };
|
2018-03-21 21:56:02 +00:00
|
|
|
|
|
|
|
parseDump(parseSink, wrapper);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-01 15:05:55 +00:00
|
|
|
void copyPath(const Path & from, const Path & to)
|
|
|
|
{
|
|
|
|
auto source = sinkToSource([&](Sink & sink) {
|
|
|
|
dumpPath(from, sink);
|
|
|
|
});
|
|
|
|
restorePath(to, *source);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|