gnu: surgescript: Update to 0.5.4.4.
[jackhill/guix/guix.git] / nix / libutil / archive.hh
CommitLineData
36457566
LC
1#pragma once
2
3#include "types.hh"
4#include "serialise.hh"
5
6
7namespace nix {
8
9
10/* dumpPath creates a Nix archive of the specified path. The format
11 is as follows:
12
13 IF path points to a REGULAR FILE:
14 dump(path) = attrs(
15 [ ("type", "regular")
16 , ("contents", contents(path))
17 ])
18
19 IF path points to a DIRECTORY:
20 dump(path) = attrs(
21 [ ("type", "directory")
22 , ("entries", concat(map(f, sort(entries(path)))))
23 ])
24 where f(fn) = attrs(
25 [ ("name", fn)
26 , ("file", dump(path + "/" + fn))
27 ])
28
29 where:
30
2bb04905 31 attrs(as) = concat(map(attr, as)) + encN(0)
36457566
LC
32 attrs((a, b)) = encS(a) + encS(b)
33
34 encS(s) = encN(len(s)) + s + (padding until next 64-bit boundary)
35
36 encN(n) = 64-bit little-endian encoding of n.
37
38 contents(path) = the contents of a regular file.
39
40 sort(strings) = lexicographic sort by 8-bit value (strcmp).
41
42 entries(path) = the entries of a directory, without `.' and
43 `..'.
44
45 `+' denotes string concatenation. */
46
47struct PathFilter
48{
49 virtual ~PathFilter() { }
50 virtual bool operator () (const Path & path) { return true; }
51};
52
53extern PathFilter defaultPathFilter;
54
55void dumpPath(const Path & path, Sink & sink,
56 PathFilter & filter = defaultPathFilter);
57
58struct ParseSink
59{
60 virtual void createDirectory(const Path & path) { };
2bb04905 61
36457566
LC
62 virtual void createRegularFile(const Path & path) { };
63 virtual void isExecutable() { };
64 virtual void preallocateContents(unsigned long long size) { };
65 virtual void receiveContents(unsigned char * data, unsigned int len) { };
66
67 virtual void createSymlink(const Path & path, const string & target) { };
68};
2bb04905 69
36457566
LC
70void parseDump(ParseSink & sink, Source & source);
71
72void restorePath(const Path & path, Source & source);
73
36457566 74}