Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git file ingestion method #1

Merged
merged 29 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f3dbfaa
Merge remote-tracking branch 'Ericson2314/enum-FileIngestionMethod' i…
matthewbauer May 27, 2020
d4aff3f
Add initial IpfsStore
matthewbauer May 27, 2020
e5281ce
Add ingestionMethodPrefix to get prefix
matthewbauer May 27, 2020
cbad8b4
Rename some variables named “recursive” to “method”
matthewbauer May 27, 2020
0b98d55
Handle g: prefix in nix store paths
matthewbauer May 27, 2020
859fbce
Don’t use FileIngestionMethod for StorePathsCommand
matthewbauer May 27, 2020
b0b6d4b
Merge remote-tracking branch 'obsidiansystems/ipfs-develop' into ipfs…
matthewbauer May 27, 2020
09a9bf0
Use git: instead of g: for ca prefix
matthewbauer May 27, 2020
44bc71b
Rename recursive to method in more places
matthewbauer May 27, 2020
fb83c10
Throw error when using unsupported git file ingestion
matthewbauer May 27, 2020
168c7d8
First draft of git parsing
meditans May 27, 2020
147764c
Use switch ingestion method in BinaryCacheStore::addToStore
matthewbauer May 28, 2020
63df19e
Merge remote-tracking branch 'obsidian/ipfs-develop' into ipfs-git-me…
Ericson2314 May 28, 2020
6c29671
Merge branch 'ipfs-develop' into ipfs-git-method
Ericson2314 May 28, 2020
17dc40c
Merge branch 'ipfs-develop' into ipfs-git-method
Ericson2314 May 28, 2020
dbca599
Add ingestionMethodPrefix to get prefix
matthewbauer May 27, 2020
9b452c9
Handle g: prefix in nix store paths
matthewbauer May 27, 2020
16c4945
Use git: instead of g: for ca prefix
matthewbauer May 27, 2020
6ba8360
Rename recursive to method in more places
matthewbauer May 27, 2020
2e16c28
Throw error when using unsupported git file ingestion
matthewbauer May 27, 2020
256bbb6
First draft of git parsing
meditans May 27, 2020
85eeb2a
Use switch ingestion method in BinaryCacheStore::addToStore
matthewbauer May 28, 2020
39df335
More work on git objects
matthewbauer May 27, 2020
77a9510
Merge branch 'git-objects' into ipfs-git-method
Ericson2314 May 28, 2020
ffc1024
Add fcntl.h to fs-sink.hh
matthewbauer May 28, 2020
35001b6
Remove `aarch64-linux` from supportedSystems until we have a builder
Ericson2314 May 27, 2020
9d82006
Remove x86-linux from supportedSystems for now, too
Ericson2314 May 27, 2020
77153be
Merge remote-tracking branch 'obsidiansystems/ipfs-develop' into git-…
matthewbauer May 28, 2020
9e820c1
Merge branch 'git-objects-develop' into ipfs-git-method
matthewbauer May 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,14 @@ StorePath BinaryCacheStore::addToStore(const string & name, const Path & srcPath
dumpPath(srcPath, sink, filter);
h = hashString(hashAlgo, *sink.s);
break;
}
case FileIngestionMethod::Flat:
case FileIngestionMethod::Flat: {
auto s = readFile(srcPath);
dumpString(s, sink);
h = hashString(hashAlgo, s);
break;
}
case FileIngestionMethod::Git:
throw Error("cannot add to binary cache store using the git file ingestion method");
default: throw;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need this to avoid the warning

}

ValidPathInfo info(makeFixedOutputPath(method, h, name));
Expand Down
9 changes: 6 additions & 3 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "local-store.hh"
#include "globals.hh"
#include "git.hh"
#include "archive.hh"
#include "pathlocks.hh"
#include "worker-protocol.hh"
Expand Down Expand Up @@ -1067,19 +1068,21 @@ StorePath LocalStore::addToStoreFromDump(const string & dump, const string & nam

autoGC();

switch method{
switch (method) {
case FileIngestionMethod::Flat:
writeFile(realPath, dump);
break;
case FileIngestionMethod::Recursive:
case FileIngestionMethod::Recursive: {
StringSource source(dump);
restorePath(realPath, source);
break;
case FileIngestionMethod::Git:
}
case FileIngestionMethod::Git: {
StringSource source(dump);
restoreGit(realPath, source);
break;
}
}

canonicalisePathMetaData(realPath, -1);

Expand Down
1 change: 0 additions & 1 deletion src/libutil/archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <fcntl.h>

#include "archive.hh"
#include "restore-sink.hh"
#include "util.hh"
#include "config.hh"

Expand Down
15 changes: 1 addition & 14 deletions src/libutil/archive.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

#include "fs-sink.hh"

namespace nix {

Expand Down Expand Up @@ -50,19 +50,6 @@ void dumpPath(const Path & path, Sink & sink,

void dumpString(const std::string & s, Sink & sink);

/* FIXME: fix this API, it sucks. */
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) { };
};

struct TeeSink : ParseSink
{
TeeSource source;
Expand Down
14 changes: 13 additions & 1 deletion src/libutil/restore-sink.hh → src/libutil/fs-sink.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

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

namespace nix {

/* FIXME: fix this API, it sucks. */
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) { };
};

struct RestoreSink : ParseSink
{
Path dstPath;
Expand Down
56 changes: 54 additions & 2 deletions src/libutil/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@

#include "util.hh"
#include "config.hh"
#include "restore-sink.hh"
#include "hash.hh"

#include "git.hh"

using namespace std::string_literals;

namespace nix {

static void parse(ParseSink & sink, Source & source, const Path & path);

// Converts a Path to a ParseSink
void restoreGit(const Path & path, Source & source) {

RestoreSink sink;
sink.dstPath = path;
parseDump(sink, source);
parseGit(sink, source);

}

Expand All @@ -49,4 +52,53 @@ static void parse(ParseSink & sink, Source & source, const Path & path) {
}
}

// Internal version, returns the perm.
unsigned int dumpGitInternal(const Path & path, Sink & sink, PathFilter & filter)
{
struct stat st;
if (lstat(path.c_str(), &st))
throw SysError(format("getting attributes of path '%1%'") % path);

if (S_ISREG(st.st_mode)) {
auto s = (format("blob %d\0%s"s) % std::to_string(st.st_size) % readFile(path)).str();

vector<unsigned char> v;
std::copy(s.begin(), s.end(), std::back_inserter(v));
sink(v.data(), v.size());
return st.st_mode & S_IXUSR
? 100755
: 100644;
}

else if (S_ISDIR(st.st_mode)) {
std::string s1 = "";

std::map<string, string> entries;
for (auto & i : readDirectory(path))
entries[i.name] = i.name;

for (auto & i : entries)
if (filter(path + "/" + i.first)) {
HashSink hashSink(htSHA1);
unsigned int perm = dumpGitInternal(path + "/" + i.first, hashSink, filter);
auto hash = hashSink.finish().first;
s1 += (format("%6d %s\0%s"s) % perm % i.first % hash.hash).str();
}

std::string s2 = (format("tree %d\0%s"s) % s1.size() % s1).str();

vector<unsigned char> v;
std::copy(s2.begin(), s2.end(), std::back_inserter(v));
sink(v.data(), v.size());
return 40000;
}

else throw Error(format("file '%1%' has an unsupported type") % path);
}

void dumpGit(const Path & path, Sink & sink, PathFilter & filter)
{
dumpGitInternal(path, sink, filter);
}

}
4 changes: 2 additions & 2 deletions src/libutil/git.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include "types.hh"
#include "serialise.hh"
#include "archive.hh"
#include "fs-sink.hh"

namespace nix {

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

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

static void parse(ParseSink & sink, Source & source, const Path & path);
void dumpGit(const Path & path, Sink & sink, PathFilter & filter = defaultPathFilter);

}
You are viewing a condensed version of this merge commit. You can view the full changes here.