Refactor local binary cache code into a subclass

[?]
Feb 18, 2016, 1:06 PM
N2NKSKHSFR6SDMGZO2ALNDVIOLOEE26BPQHCSWUGEFE3DVVVV4MAC

Dependencies

  • [2] GH4S4AWM Rename file
  • [3] W2AOTSS6 Rename class
  • [4] 24BMQDZA Start of single-process hydra-queue-runner
  • [5] 5AIYUMTB Basic remote building
  • [6] MHVIT4JY Split hydra-queue-runner.cc more
  • [7] 3FQ65IXO hydra-queue-runner: Compress binary cache NARs using xz
  • [8] 32HHP5CW hydra-queue-runner: Support generating a signed binary cache
  • [9] 73YR46NJ hydra-queue-runner: Write directly to a binary cache
  • [10] ENXUSMSV Make concurrency more robust
  • [11] HJOEIMLR Refactor

Change contents

  • replacement in src/hydra-queue-runner/Makefile.am at line 6
    [4.77][2.0:45]()
    binary-cache-store.hh binary-cache-store.cc
    [4.77]
    [4.322]
    binary-cache-store.hh binary-cache-store.cc \
    local-binary-cache-store.hh local-binary-cache-store.cc
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 12
    [4.2032][3.0:87]()
    BinaryCacheStore::BinaryCacheStore(ref<Store> localStore, const Path & binaryCacheDir,
    [4.2032]
    [4.307]
    BinaryCacheStore::BinaryCacheStore(ref<Store> localStore,
  • edit in src/hydra-queue-runner/binary-cache-store.cc at line 15
    [4.396][4.396:433]()
    , binaryCacheDir(binaryCacheDir)
  • edit in src/hydra-queue-runner/binary-cache-store.cc at line 16
    [4.2182][4.2182:2223](),[4.2223][4.434:608]()
    createDirs(binaryCacheDir + "/nar");
    Path cacheInfoFile = binaryCacheDir + "/nix-cache-info";
    if (!pathExists(cacheInfoFile))
    writeFile(cacheInfoFile, "StoreDir: " + settings.nixStore + "\n");
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 26
    [4.2226][3.88:150]()
    Path BinaryCacheStore::narInfoFileFor(const Path & storePath)
    [4.2226]
    [4.2288]
    void BinaryCacheStore::init()
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 28
    [4.2290][4.2290:2397]()
    assertStorePath(storePath);
    return binaryCacheDir + "/" + storePathToHash(storePath) + ".narinfo";
    [4.2290]
    [4.2397]
    std::string cacheInfoFile = "nix-cache-info";
    if (!fileExists(cacheInfoFile))
    upsertFile(cacheInfoFile, "StoreDir: " + settings.nixStore + "\n");
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 33
    [4.2400][4.2400:2459]()
    void atomicWrite(const Path & path, const std::string & s)
    [4.2400]
    [4.2459]
    Path BinaryCacheStore::narInfoFileFor(const Path & storePath)
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 35
    [4.2461][4.2461:2715]()
    Path tmp = path + ".tmp." + std::to_string(getpid());
    AutoDelete del(tmp, false);
    writeFile(tmp, s);
    if (rename(tmp.c_str(), path.c_str()))
    throw SysError(format("renaming ‘%1%’ to ‘%2%’") % tmp % path);
    del.cancel();
    [4.2461]
    [4.2715]
    assertStorePath(storePath);
    return storePathToHash(storePath) + ".narinfo";
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 42
    [4.2806][4.27:118]()
    Path narInfoFile = narInfoFileFor(info.path);
    if (pathExists(narInfoFile)) return;
    [4.2806]
    [4.929]
    auto narInfoFile = narInfoFileFor(info.path);
    if (fileExists(narInfoFile)) return;
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 64
    [4.1349][4.1349:1404](),[4.1404][4.306:365](),[4.3328][4.306:365]()
    Path narFile = binaryCacheDir + "/" + narInfo.url;
    if (!pathExists(narFile)) atomicWrite(narFile, narXz);
    [4.1349]
    [4.3385]
    if (!fileExists(narInfo.url)) upsertFile(narInfo.url, narXz);
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 69
    [4.3519][4.1451:1502]()
    atomicWrite(narInfoFile, narInfo.to_string());
    [4.3519]
    [4.4219]
    upsertFile(narInfoFile, narInfo.to_string());
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 74
    [4.4322][4.4322:4372](),[4.4372][4.1566:1633]()
    Path narInfoFile = narInfoFileFor(storePath);
    NarInfo narInfo = NarInfo(readFile(narInfoFile), narInfoFile);
    [4.4304]
    [4.1633]
    auto narInfoFile = narInfoFileFor(storePath);
    auto narInfo = NarInfo(getFile(narInfoFile), narInfoFile);
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 88
    [4.5652][4.1862:1912]()
    return pathExists(narInfoFileFor(storePath));
    [4.5652]
    [4.5821]
    return fileExists(narInfoFileFor(storePath));
  • replacement in src/hydra-queue-runner/binary-cache-store.cc at line 97
    [4.5968][4.1913:1970]()
    auto nar = readFile(binaryCacheDir + "/" + res.url);
    [4.5968]
    [4.1104]
    auto nar = getFile(res.url);
  • replacement in src/hydra-queue-runner/binary-cache-store.hh at line 10
    [4.9310][3.828:871]()
    class BinaryCacheStore : public nix::Store
    [4.9310]
    [4.9353]
    class BinaryCacheStore : public Store
  • edit in src/hydra-queue-runner/binary-cache-store.hh at line 13
    [4.9364]
    [4.9364]
  • edit in src/hydra-queue-runner/binary-cache-store.hh at line 15
    [4.9391][4.9391:9416]()
    Path binaryCacheDir;
  • replacement in src/hydra-queue-runner/binary-cache-store.hh at line 19
    [4.9417][4.9417:9425]()
    public:
    [4.9417]
    [4.9425]
    protected:
  • replacement in src/hydra-queue-runner/binary-cache-store.hh at line 21
    [4.9426][3.872:945]()
    BinaryCacheStore(ref<Store> localStore, const Path & binaryCacheDir,
    [4.9426]
    [4.2300]
    BinaryCacheStore(ref<Store> localStore,
  • edit in src/hydra-queue-runner/binary-cache-store.hh at line 23
    [4.2365]
    [4.9500]
    virtual bool fileExists(const std::string & path) = 0;
    virtual void upsertFile(const std::string & path, const std::string & data) = 0;
    virtual std::string getFile(const std::string & path) = 0;
    public:
  • edit in src/hydra-queue-runner/binary-cache-store.hh at line 32
    [4.9501]
    [4.9501]
    virtual void init();
  • replacement in src/hydra-queue-runner/binary-cache-store.hh at line 36
    [4.9511][4.9511:9560]()
    Path narInfoFileFor(const Path & storePath);
    [4.9511]
    [4.9560]
    std::string narInfoFileFor(const Path & storePath);
  • replacement in src/hydra-queue-runner/hydra-queue-runner.cc at line 10
    [4.20065][2.170:203]()
    #include "binary-cache-store.hh"
    [4.20065]
    [4.19]
    #include "local-binary-cache-store.hh"
  • replacement in src/hydra-queue-runner/hydra-queue-runner.cc at line 36
    [4.1660][3.946:1001]()
    return make_ref<BinaryCacheStore>(getLocalStore(),
    [4.1660]
    [4.55]
    auto store = make_ref<LocalBinaryCacheStore>(getLocalStore(),
  • edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 40
    [4.195]
    [4.7503]
    store->init();
    return store;
  • file addition: local-binary-cache-store.cc (----------)
    [4.187]
    #include "local-binary-cache-store.hh"
    namespace nix {
    LocalBinaryCacheStore::LocalBinaryCacheStore(ref<Store> localStore,
    const Path & binaryCacheDir, const Path & secretKeyFile, const Path & publicKeyFile)
    : BinaryCacheStore(localStore, secretKeyFile, publicKeyFile)
    , binaryCacheDir(binaryCacheDir)
    {
    }
    void LocalBinaryCacheStore::init()
    {
    createDirs(binaryCacheDir + "/nar");
    BinaryCacheStore::init();
    }
    static void atomicWrite(const Path & path, const std::string & s)
    {
    Path tmp = path + ".tmp." + std::to_string(getpid());
    AutoDelete del(tmp, false);
    writeFile(tmp, s);
    if (rename(tmp.c_str(), path.c_str()))
    throw SysError(format("renaming ‘%1%’ to ‘%2%’") % tmp % path);
    del.cancel();
    }
    bool LocalBinaryCacheStore::fileExists(const std::string & path)
    {
    return pathExists(binaryCacheDir + "/" + path);
    }
    void LocalBinaryCacheStore::upsertFile(const std::string & path, const std::string & data)
    {
    atomicWrite(binaryCacheDir + "/" + path, data);
    }
    std::string LocalBinaryCacheStore::getFile(const std::string & path)
    {
    return readFile(binaryCacheDir + "/" + path);
    }
    }
  • file addition: local-binary-cache-store.hh (----------)
    [4.187]
    #pragma once
    #include "binary-cache-store.hh"
    namespace nix {
    class LocalBinaryCacheStore : public BinaryCacheStore
    {
    private:
    Path binaryCacheDir;
    public:
    LocalBinaryCacheStore(ref<Store> localStore, const Path & binaryCacheDir,
    const Path & secretKeyFile, const Path & publicKeyFile);
    void init() override;
    protected:
    bool fileExists(const std::string & path) override;
    void upsertFile(const std::string & path, const std::string & data) override;
    std::string getFile(const std::string & path) override;
    };
    }