2012-07-18 18:59:03 +00:00
|
|
|
#pragma once
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
#include "types.hh"
|
2006-11-30 19:19:59 +00:00
|
|
|
#include "serialise.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
2003-06-20 10:40:25 +00: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 14:02:05 +00:00
|
|
|
attrs(as) = concat(map(attr, as)) + encN(0)
|
2003-06-20 10:40:25 +00: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 21:51:02 +00:00
|
|
|
|
|
|
|
void dumpPath(const Path & path, Sink & sink,
|
2006-12-12 23:05:01 +00:00
|
|
|
PathFilter & filter = defaultPathFilter);
|
2003-06-20 10:40:25 +00:00
|
|
|
|
2016-02-24 15:52:28 +00:00
|
|
|
void dumpString(const std::string & s, Sink & sink);
|
|
|
|
|
2016-02-25 16:43:19 +00:00
|
|
|
/* FIXME: fix this API, it sucks. */
|
2008-12-03 17:30:32 +00:00
|
|
|
struct ParseSink
|
|
|
|
{
|
|
|
|
virtual void createDirectory(const Path & path) { };
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2008-12-03 17:30:32 +00:00
|
|
|
virtual void createRegularFile(const Path & path) { };
|
|
|
|
virtual void isExecutable() { };
|
2009-03-22 17:36:43 +00:00
|
|
|
virtual void preallocateContents(unsigned long long size) { };
|
2008-12-03 17:30:32 +00:00
|
|
|
virtual void receiveContents(unsigned char * data, unsigned int len) { };
|
|
|
|
|
|
|
|
virtual void createSymlink(const Path & path, const string & target) { };
|
|
|
|
};
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2020-07-10 18:58:02 +00:00
|
|
|
struct TeeParseSink : ParseSink
|
2017-03-01 15:16:04 +00:00
|
|
|
{
|
2020-07-13 15:30:42 +00:00
|
|
|
StringSink saved;
|
2017-03-01 15:16:04 +00:00
|
|
|
TeeSource source;
|
|
|
|
|
2020-07-13 15:30:42 +00:00
|
|
|
TeeParseSink(Source & source) : source(source, saved) { }
|
2017-03-01 15:16:04 +00:00
|
|
|
};
|
|
|
|
|
2008-12-03 17:30:32 +00:00
|
|
|
void parseDump(ParseSink & sink, Source & source);
|
|
|
|
|
2006-11-30 19:19:59 +00:00
|
|
|
void restorePath(const Path & path, Source & source);
|
2006-09-04 21:06:23 +00:00
|
|
|
|
2018-03-21 21:56:02 +00:00
|
|
|
/* Read a NAR from 'source' and write it to 'sink'. */
|
|
|
|
void copyNAR(Source & source, Sink & sink);
|
|
|
|
|
2018-10-01 15:05:55 +00:00
|
|
|
void copyPath(const Path & from, const Path & to);
|
|
|
|
|
2014-07-16 14:02:05 +00:00
|
|
|
|
2016-02-24 15:52:28 +00:00
|
|
|
extern const std::string narVersionMagic1;
|
|
|
|
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|