From 67684b3a9a7205cef15f5978b5adc4df632f5af5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 21 Jul 2019 13:54:41 +0100 Subject: Basically all the core functionality --- src/blob.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'src/blob.cpp') diff --git a/src/blob.cpp b/src/blob.cpp index 8fb0509..4bd8b15 100644 --- a/src/blob.cpp +++ b/src/blob.cpp @@ -1,13 +1,39 @@ #include +#include #include "blob.h" +#include "repo.h" -GitFS::Blob::Blob(const GitFS::Git::RepositoryPtr & r, const GitFS::Git::TreeEntryPtr & te) : - blob(Git::BlobLookup(r, *git_tree_entry_id(te.get()))), +GitFS::Blob::Blob(const Repo * r, const std::string & path) : + repo(r), + entry(getTreeEntry(path)), + blob(getBlob()), blobSize(git_blob_rawsize(blob.get())), blobContent(static_cast(git_blob_rawcontent(blob.get()))) { } +GitFS::Git::TreeEntryPtr +GitFS::Blob::getTreeEntry(const std::string & path) const +{ + try { + return Git::TreeEntryByPath(repo->tree, path); + } + catch (const Git::Error & e) { + Git::ErrorToSystemError(e); + } +} + +GitFS::Git::BlobPtr +GitFS::Blob::getBlob() const +{ + const auto mode = git_tree_entry_filemode(entry.get()); + + if (S_ISDIR(mode)) throw NetFS::SystemError(EISDIR); + if (S_ISLNK(mode)) throw NetFS::SystemError(ELOOP); + + return Git::BlobLookup(repo->repo, *git_tree_entry_id(entry.get())); +} + void GitFS::Blob::close(const ::Ice::Current& current) { @@ -18,7 +44,10 @@ GitFS::Blob::close(const ::Ice::Current& current) NetFS::Attr GitFS::Blob::fgetattr(ReqEnv, const ::Ice::Current&) { - return {}; + NetFS::Attr a; + a << *blob << *entry << *repo->commit; + a.gid = a.uid = "root"; + return a; } -- cgit v1.2.3