diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-21 13:54:41 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-21 13:54:41 +0100 |
commit | 67684b3a9a7205cef15f5978b5adc4df632f5af5 (patch) | |
tree | 630a28d313047bf6440b0c349047c6c8de0cb298 /src/blob.cpp | |
parent | Add a test symlink (diff) | |
download | netfs-gitfs-67684b3a9a7205cef15f5978b5adc4df632f5af5.tar.bz2 netfs-gitfs-67684b3a9a7205cef15f5978b5adc4df632f5af5.tar.xz netfs-gitfs-67684b3a9a7205cef15f5978b5adc4df632f5af5.zip |
Basically all the core functionality
Diffstat (limited to 'src/blob.cpp')
-rw-r--r-- | src/blob.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
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 <Ice/ObjectAdapter.h> +#include <sys/stat.h> #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<const char *>(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; } |