aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/misc.cc
blob: 2757a061ece20d50f2aa7443dc13178968edc71d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "normalise.hh"


Derivation derivationFromPath(const Path & drvPath)
{
    assertStorePath(drvPath);
    ensurePath(drvPath);
    ATerm t = ATreadFromNamedFile(drvPath.c_str());
    if (!t) throw Error(format("cannot read aterm from `%1%'") % drvPath);
    return parseDerivation(t);
}


void computeFSClosure(const Path & storePath,
    PathSet & paths)
{
    if (paths.find(storePath) != paths.end()) return;
    paths.insert(storePath);

    PathSet references;
    queryReferences(storePath, references);

    for (PathSet::iterator i = references.begin();
         i != references.end(); ++i)
        computeFSClosure(*i, paths);
}


void storePathRequisites(const Path & storePath,
    bool includeOutputs, PathSet & paths)
{
    checkInterrupt();
    
    if (paths.find(storePath) != paths.end()) return;

    if (isDerivation(storePath)) {

        paths.insert(storePath);
        
        Derivation drv = derivationFromPath(storePath);

        for (PathSet::iterator i = drv.inputDrvs.begin();
             i != drv.inputDrvs.end(); ++i)
            storePathRequisites(*i, includeOutputs, paths);

        for (PathSet::iterator i = drv.inputSrcs.begin();
             i != drv.inputSrcs.end(); ++i)
            storePathRequisites(*i, includeOutputs, paths);

        if (includeOutputs) {

            for (DerivationOutputs::iterator i = drv.outputs.begin();
                 i != drv.outputs.end(); ++i)
                if (isValidPath(i->second.path))
                    storePathRequisites(i->second.path, includeOutputs, paths);

        }
        
    }

    else {
        computeFSClosure(storePath, paths);
    }
}