LTP GCOV extension - code coverage report
Current view: directory - src/libstore - upgrade-schema.cc
Test: app.info
Date: 2008-11-20 Instrumented lines: 31
Code covered: 6.5 % Executed lines: 2

       1                 : #include "db.hh"
       2                 : #include "hash.hh"
       3                 : #include "util.hh"
       4                 : #include "local-store.hh"
       5                 : #include "globals.hh"
       6                 : #include "pathlocks.hh"
       7                 : #include "config.h"
       8                 : 
       9                 : #include <iostream>
      10                 : 
      11                 : 
      12                 : namespace nix {
      13                 : 
      14                 : 
      15                 : Hash parseHashField(const Path & path, const string & s);
      16                 : 
      17                 : 
      18                 : /* Upgrade from schema 4 (Nix 0.11) to schema 5 (Nix >= 0.12).  The
      19                 :    old schema uses Berkeley DB, the new one stores store path
      20                 :    meta-information in files. */
      21               0 : void LocalStore::upgradeStore12()
      22                 : {
      23                 : #if OLD_DB_COMPAT
      24                 :     
      25                 : #ifdef __CYGWIN__
      26                 :     /* Cygwin can't upgrade a read lock to a write lock... */
      27                 :     lockFile(globalLock, ltNone, true);
      28                 : #endif
      29                 : 
      30               0 :     if (!lockFile(globalLock, ltWrite, false)) {
      31               0 :         printMsg(lvlError, "waiting for exclusive access to the Nix store...");
      32               0 :         lockFile(globalLock, ltWrite, true);
      33                 :     }
      34                 : 
      35               0 :     printMsg(lvlError, "upgrading Nix store to new schema (this may take a while)...");
      36                 : 
      37               0 :     if (getSchema() >= nixSchemaVersion) return; /* somebody else beat us to it */
      38                 : 
      39                 :     /* Open the old Nix database and tables. */
      40               0 :     Database nixDB;
      41               0 :     nixDB.open(nixDBPath);
      42                 :     
      43                 :     /* dbValidPaths :: Path -> ()
      44                 : 
      45                 :        The existence of a key $p$ indicates that path $p$ is valid
      46                 :        (that is, produced by a succesful build). */
      47               0 :     TableId dbValidPaths = nixDB.openTable("validpaths");
      48                 : 
      49                 :     /* dbReferences :: Path -> [Path]
      50                 : 
      51                 :        This table lists the outgoing file system references for each
      52                 :        output path that has been built by a Nix derivation.  These are
      53                 :        found by scanning the path for the hash components of input
      54                 :        paths. */
      55               0 :     TableId dbReferences = nixDB.openTable("references");
      56                 : 
      57                 :     /* dbReferrers :: Path -> Path
      58                 : 
      59                 :        This table is just the reverse mapping of dbReferences.  This
      60                 :        table can have duplicate keys, each corresponding value
      61                 :        denoting a single referrer. */
      62                 :     // Not needed for conversion: it's just the inverse of
      63                 :     // references.
      64                 :     // TableId dbReferrers = nixDB.openTable("referrers");
      65                 : 
      66                 :     /* dbDerivers :: Path -> [Path]
      67                 : 
      68                 :        This table lists the derivation used to build a path.  There
      69                 :        can only be multiple such paths for fixed-output derivations
      70                 :        (i.e., derivations specifying an expected hash). */
      71               0 :     TableId dbDerivers = nixDB.openTable("derivers");
      72                 : 
      73               0 :     Paths paths;
      74               0 :     nixDB.enumTable(noTxn, dbValidPaths, paths);
      75                 :     
      76               0 :     for (Paths::iterator i = paths.begin(); i != paths.end(); ++i) {
      77               0 :         ValidPathInfo info;
      78               0 :         info.path = *i;
      79                 :         
      80               0 :         Paths references;
      81               0 :         nixDB.queryStrings(noTxn, dbReferences, *i, references);
      82               0 :         info.references.insert(references.begin(), references.end());
      83                 :         
      84               0 :         string s;
      85               0 :         nixDB.queryString(noTxn, dbValidPaths, *i, s);
      86               0 :         info.hash = parseHashField(*i, s);
      87                 :         
      88               0 :         nixDB.queryString(noTxn, dbDerivers, *i, info.deriver);
      89                 :         
      90               0 :         registerValidPath(info, true);
      91               0 :         std::cerr << ".";
      92                 :     }
      93                 : 
      94               0 :     std::cerr << std::endl;
      95                 : 
      96               0 :     writeFile(schemaPath, (format("%1%") % nixSchemaVersion).str());
      97                 : 
      98               0 :     lockFile(globalLock, ltRead, true);
      99                 : 
     100                 : #else
     101                 :     throw Error(
     102                 :         "Your Nix store has a database in Berkeley DB format. To convert\n"
     103                 :         "to the new format, please compile Nix with Berkeley DB support.");
     104                 : #endif
     105                 : }
     106                 : 
     107               0 : 
     108            1106 : }

Generated by: LTP GCOV extension version 1.6