| 1 | #pragma once
|
| 2 |
|
| 3 | #include "types.hh"
|
| 4 | #include "serialise.hh"
|
| 5 |
|
| 6 |
|
| 7 | namespace nix {
|
| 8 |
|
| 9 |
|
| 10 | |
| 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 |
|
| 31 | attrs(as) = concat(map(attr, as)) + encN(0)
|
| 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 |
|
| 47 | struct PathFilter
|
| 48 | {
|
| 49 | virtual ~PathFilter() { }
|
| 50 | virtual bool operator () (const Path & path) { return true; }
|
| 51 | };
|
| 52 |
|
| 53 | inline PathFilter defaultPathFilter;
|
| 54 |
|
| 55 | void dumpPath(const Path & path, Sink & sink,
|
| 56 | PathFilter & filter = defaultPathFilter);
|
| 57 |
|
| 58 | struct ParseSink
|
| 59 | {
|
| 60 | virtual void createDirectory(const Path & path) { };
|
| 61 |
|
| 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 | };
|
| 69 |
|
| 70 | void parseDump(ParseSink & sink, Source & source);
|
| 71 |
|
| 72 | void restorePath(const Path & path, Source & source);
|
| 73 |
|
| 74 | }
|