2006-09-04 23:06:23 +02:00
|
|
|
#ifndef __ARCHIVE_H
|
|
|
|
#define __ARCHIVE_H
|
2003-06-20 12:40:25 +02:00
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
#include "types.hh"
|
2006-11-30 20:19:59 +01:00
|
|
|
#include "serialise.hh"
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
namespace nix {
|
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. */
|
|
|
|
|
2006-11-30 20:19:59 +01:00
|
|
|
void dumpPath(const Path & path, Sink & sink);
|
2003-06-20 12:40:25 +02:00
|
|
|
|
2006-11-30 20:19:59 +01:00
|
|
|
void restorePath(const Path & path, Source & source);
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !__ARCHIVE_H */
|