aboutsummaryrefslogtreecommitdiff
#pragma once

#include "types.hh"
#include "serialise.hh"


namespace nix {


/* 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 PathFilter
{
    virtual ~PathFilter() { }
    virtual bool operator () (const Path & path) { return true; }
};

extern PathFilter defaultPathFilter;

void dumpPath(const Path & path, Sink & sink,
    PathFilter & filter = defaultPathFilter);

struct ParseSink
{
    virtual void createDirectory(const Path & path) { };

    virtual void createRegularFile(const Path & path) { };
    virtual void isExecutable() { };
    virtual void preallocateContents(unsigned long long size) { };
    virtual void receiveContents(unsigned char * data, unsigned int len) { };

    virtual void createSymlink(const Path & path, const string & target) { };
};

void parseDump(ParseSink & sink, Source & source);

void restorePath(const Path & path, Source & source);

}
21-12-17lint: Adjust patch file length check....Vagrant Cascadian 2021-11-08Merge remote-tracking branch 'origin/master' into core-updates-frozenEfraim Flashner 2021-11-06tests: Avoid literal strings for invalid Texinfo markup....Ludovic Courtès 2021-10-31Merge remote-tracking branch 'origin/master' into core-updates-frozenEfraim Flashner 2021-10-24lint: Add description check for common typos....Vagrant Cascadian 2021-10-12Merge remote-tracking branch 'origin/master' into core-updates-frozen.Mathieu Othacehe 2021-10-02import: stackage: Use 'define-json-mapping'....Ludovic Courtès 2021-09-28test: lint: Fix ‘haskell-stackage’ test....Xinglu Chen 2021-07-18Merge branch 'master' into core-updatesLudovic Courtès 2021-07-13lint: Check for leading whitespace in description....Brice Waegeneire 2021-07-11lint: Add 'input-labels' checker....Ludovic Courtès 2021-07-07lint: Lint usages of 'wrap-program' without a "bash" input....Maxime Devos 2021-06-30lint: Verify if #:tests? is respected in the 'check' phase....Maxime Devos 2021-06-19Merge branch 'master' into core-updates...Marius Bakke 2021-06-08lint: Check for trailing whitespace in description....Xinglu Chen 2021-06-08lint: Check for trailing whitespace in synopsis....Xinglu Chen 2021-06-06Merge branch 'master' into core-updates...Marius Bakke 2021-06-06lint: tests-true: Check if tests are enabled when cross-compiling....Maxime Devos 2021-05-22lint: archival: Lookup content in Disarchive database....Ludovic Courtès 2021-05-09Merge branch 'master' into core-updates...Marius Bakke 2021-04-16lint: Warn about underscores in package names....Xinglu Chen 2021-03-30build-system: Rewrite using gexps....Ludovic Courtès 2021-03-13tests: Remove obsolete comment....Tobias Geerinckx-Rice 2021-03-06tests: do not hard code HTTP ports...Maxime Devos 2020-12-07tests: lint: Add origin patch file name test cases....Chris Marusich 2020-11-21lint: Add 'check-haskell-stackage' checker....Timothy Sample 2020-11-21lint: Add 'patch-headers' checker....Ludovic Courtès 2020-07-25Use 'formatted-message' instead of '&message' where appropriate....Ludovic Courtès 2020-07-12gnu: Remove ".git" from "https://github/…/….git"....Ludovic Courtès 2020-07-12lint: source: Validate URLs of Git references....Ludovic Courtès 2020-06-26tests: Skip lint tests when HTTP server cannot listen....Ludovic Courtès 2020-06-14lint: Add 'check-for-collisions' checker....Ludovic Courtès 2020-01-17lint: vulnerabilities: Avoid 'mock' in test....Ludovic Courtès 2019-10-20tests: Avoid now-deprecated 'make-struct'....Ludovic Courtès 2019-09-02lint: Add 'archival' checker....Ludovic Courtès 2019-09-02tests: 'with-http-server' accepts multiple responses....Ludovic Courtès 2019-08-17tests: Relax expectations for the 'home-page' checker....Ludovic Courtès 2019-07-20lint: Add test for 'source'....Ludovic Courtès 2019-07-20lint: Update tests to (guix lint) migration....Ludovic Courtès 2019-07-15lint: Move the linting code to a different module....Christopher Baines 2019-07-15scripts: lint: Handle warnings with a record type....Christopher Baines