2003-06-20 12:40:25 +02:00
|
|
|
#include <string>
|
|
|
|
|
2003-10-08 17:06:59 +02:00
|
|
|
#include "util.hh"
|
2003-06-20 12:40:25 +02: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:
|
|
|
|
|
|
|
|
attrs(as) = concat(map(attr, as)) + encN(0)
|
|
|
|
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. */
|
|
|
|
|
|
|
|
struct DumpSink
|
|
|
|
{
|
2005-03-03 14:58:02 +01:00
|
|
|
virtual ~DumpSink() { }
|
2003-06-20 12:40:25 +02:00
|
|
|
virtual void operator () (const unsigned char * data, unsigned int len) = 0;
|
|
|
|
};
|
|
|
|
|
2003-10-08 17:06:59 +02:00
|
|
|
void dumpPath(const Path & path, DumpSink & sink);
|
2003-06-20 16:11:31 +02:00
|
|
|
|
|
|
|
|
2003-06-23 15:27:59 +02:00
|
|
|
struct RestoreSource
|
2003-06-20 16:11:31 +02:00
|
|
|
{
|
2005-03-03 14:58:02 +01:00
|
|
|
virtual ~RestoreSource() { }
|
|
|
|
|
2003-06-20 16:11:31 +02:00
|
|
|
/* The callee should store exactly *len bytes in the buffer
|
|
|
|
pointed to by data. It should block if that much data is not
|
|
|
|
yet available, or throw an error if it is not going to be
|
|
|
|
available. */
|
2003-07-20 23:11:43 +02:00
|
|
|
virtual void operator () (unsigned char * data, unsigned int len) = 0;
|
2003-06-20 16:11:31 +02:00
|
|
|
};
|
2003-06-23 15:27:59 +02:00
|
|
|
|
2003-10-08 17:06:59 +02:00
|
|
|
void restorePath(const Path & path, RestoreSource & source);
|