2012-07-18 14:59:03 -04:00
|
|
|
#pragma once
|
2003-06-20 06:40:25 -04:00
|
|
|
|
2006-09-04 17:06:23 -04:00
|
|
|
#include "types.hh"
|
2006-11-30 14:19:59 -05:00
|
|
|
#include "serialise.hh"
|
2006-09-04 17:06:23 -04:00
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
2003-06-20 06:40:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
/* dumpPath creates a Nix archive of the specified path. The format
|
|
|
|
is as follows:
|
|
|
|
|
|
|
|
IF path points to a REGULAR FILE:
|
|
|
|
dump(path) = attrs(
|
|
|
|
[ ("type", "regular")
|
|
|
|
, ("contents", contents(path))
|
|
|
|
])
|
|
|
|
|
|
|
|
IF path points to a DIRECTORY:
|
|
|
|
dump(path) = attrs(
|
|
|
|
[ ("type", "directory")
|
|
|
|
, ("entries", concat(map(f, sort(entries(path)))))
|
|
|
|
])
|
|
|
|
where f(fn) = attrs(
|
|
|
|
[ ("name", fn)
|
|
|
|
, ("file", dump(path + "/" + fn))
|
|
|
|
])
|
|
|
|
|
|
|
|
where:
|
|
|
|
|
2014-07-16 10:02:05 -04:00
|
|
|
attrs(as) = concat(map(attr, as)) + encN(0)
|
2003-06-20 06:40:25 -04:00
|
|
|
attrs((a, b)) = encS(a) + encS(b)
|
|
|
|
|
|
|
|
encS(s) = encN(len(s)) + s + (padding until next 64-bit boundary)
|
|
|
|
|
|
|
|
encN(n) = 64-bit little-endian encoding of n.
|
|
|
|
|
|
|
|
contents(path) = the contents of a regular file.
|
|
|
|
|
|
|
|
sort(strings) = lexicographic sort by 8-bit value (strcmp).
|
|
|
|
|
|
|
|
entries(path) = the entries of a directory, without `.' and
|
|
|
|
`..'.
|
|
|
|
|
|
|
|
`+' denotes string concatenation. */
|
|
|
|
|
2006-12-12 16:51:02 -05:00
|
|
|
|
|
|
|
void dumpPath(const Path & path, Sink & sink,
|
2006-12-12 18:05:01 -05:00
|
|
|
PathFilter & filter = defaultPathFilter);
|
2003-06-20 06:40:25 -04:00
|
|
|
|
2022-02-18 10:56:35 -05:00
|
|
|
/* Same as `void dumpPath()`, but returns the last modified date of the path */
|
|
|
|
time_t dumpPathAndGetMtime(const Path & path, Sink & sink,
|
|
|
|
PathFilter & filter = defaultPathFilter);
|
|
|
|
|
2022-02-25 10:00:00 -05:00
|
|
|
void dumpString(std::string_view s, Sink & sink);
|
2016-02-24 10:52:28 -05:00
|
|
|
|
2016-02-25 11:43:19 -05:00
|
|
|
/* FIXME: fix this API, it sucks. */
|
2008-12-03 12:30:32 -05:00
|
|
|
struct ParseSink
|
|
|
|
{
|
|
|
|
virtual void createDirectory(const Path & path) { };
|
2014-07-16 10:02:05 -04:00
|
|
|
|
2008-12-03 12:30:32 -05:00
|
|
|
virtual void createRegularFile(const Path & path) { };
|
|
|
|
virtual void isExecutable() { };
|
2020-07-30 07:10:49 -04:00
|
|
|
virtual void preallocateContents(uint64_t size) { };
|
2020-12-02 08:00:43 -05:00
|
|
|
virtual void receiveContents(std::string_view data) { };
|
2008-12-03 12:30:32 -05:00
|
|
|
|
2022-02-25 10:00:00 -05:00
|
|
|
virtual void createSymlink(const Path & path, const std::string & target) { };
|
2008-12-03 12:30:32 -05:00
|
|
|
};
|
2014-07-16 10:02:05 -04:00
|
|
|
|
2020-07-16 01:09:41 -04:00
|
|
|
/* If the NAR archive contains a single file at top-level, then save
|
|
|
|
the contents of the file to `s'. Otherwise barf. */
|
|
|
|
struct RetrieveRegularNARSink : ParseSink
|
2017-03-01 10:16:04 -05:00
|
|
|
{
|
2020-07-16 01:09:41 -04:00
|
|
|
bool regular = true;
|
|
|
|
Sink & sink;
|
2017-03-01 10:16:04 -05:00
|
|
|
|
2020-07-16 01:09:41 -04:00
|
|
|
RetrieveRegularNARSink(Sink & sink) : sink(sink) { }
|
|
|
|
|
2020-12-02 08:00:43 -05:00
|
|
|
void createDirectory(const Path & path) override
|
2020-07-16 01:09:41 -04:00
|
|
|
{
|
|
|
|
regular = false;
|
|
|
|
}
|
|
|
|
|
2020-12-02 08:00:43 -05:00
|
|
|
void receiveContents(std::string_view data) override
|
2020-07-16 01:09:41 -04:00
|
|
|
{
|
2020-12-02 08:00:43 -05:00
|
|
|
sink(data);
|
2020-07-16 01:09:41 -04:00
|
|
|
}
|
|
|
|
|
2022-02-25 10:00:00 -05:00
|
|
|
void createSymlink(const Path & path, const std::string & target) override
|
2020-07-16 01:09:41 -04:00
|
|
|
{
|
|
|
|
regular = false;
|
|
|
|
}
|
2017-03-01 10:16:04 -05:00
|
|
|
};
|
|
|
|
|
2008-12-03 12:30:32 -05:00
|
|
|
void parseDump(ParseSink & sink, Source & source);
|
|
|
|
|
2006-11-30 14:19:59 -05:00
|
|
|
void restorePath(const Path & path, Source & source);
|
2006-09-04 17:06:23 -04:00
|
|
|
|
2018-03-21 17:56:02 -04:00
|
|
|
/* Read a NAR from 'source' and write it to 'sink'. */
|
|
|
|
void copyNAR(Source & source, Sink & sink);
|
|
|
|
|
2018-10-01 11:05:55 -04:00
|
|
|
void copyPath(const Path & from, const Path & to);
|
|
|
|
|
2014-07-16 10:02:05 -04:00
|
|
|
|
2016-02-24 10:52:28 -05:00
|
|
|
extern const std::string narVersionMagic1;
|
|
|
|
|
|
|
|
|
2006-09-04 17:06:23 -04:00
|
|
|
}
|