summaryrefslogtreecommitdiff
path: root/src/blob.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/blob.cpp')
-rw-r--r--src/blob.cpp35
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;
}