summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blob.cpp6
-rw-r--r--src/dir.cpp10
-rw-r--r--src/repo.cpp27
-rw-r--r--src/repo.h2
4 files changed, 25 insertions, 20 deletions
diff --git a/src/blob.cpp b/src/blob.cpp
index 285cd0b..bc1f485 100644
--- a/src/blob.cpp
+++ b/src/blob.cpp
@@ -39,11 +39,7 @@ GitFS::Blob::close(const ::Ice::Current & ice)
NetFS::Attr
GitFS::Blob::fgetattr(const ::Ice::Current &)
{
- NetFS::Attr attr;
- attr << *blob << *entry << *repo->commit;
- attr.gid = repo->gid;
- attr.uid = repo->uid;
- return attr;
+ return repo->getattr(entry.get(), blob.get());
}
NetFS::Buffer
diff --git a/src/dir.cpp b/src/dir.cpp
index c608259..a825cc8 100644
--- a/src/dir.cpp
+++ b/src/dir.cpp
@@ -67,15 +67,7 @@ GitFS::Directory::listdir(const ::Ice::Current &)
NetFS::DirectoryContents list;
for (auto idx = git_tree_entrycount(subTree.get()); idx--;) {
const auto entry = git_tree_entry_byindex(subTree.get(), idx);
- NetFS::Attr attr {};
- attr << *entry << *repo->commit;
- if (S_ISREG(git_tree_entry_filemode(entry))) {
- auto blob = Git::blobLookup(repo->repo, *git_tree_entry_id(entry));
- attr << *blob;
- }
- attr.gid = repo->gid;
- attr.uid = repo->uid;
- list.emplace(git_tree_entry_name(entry), std::move(attr));
+ list.emplace(git_tree_entry_name(entry), repo->getattr(entry));
}
return list;
}
diff --git a/src/repo.cpp b/src/repo.cpp
index 6bf442f..db21e61 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -120,16 +120,31 @@ GitFS::Repo::getattr(ReqEnv, const ::std::string path, const ::Ice::Current &)
throw NetFS::SystemError(EINVAL);
}
- NetFS::Attr attr {};
+ update();
if (path == "/") {
+ NetFS::Attr attr = getattr(nullptr, nullptr);
attr.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ return attr;
}
- else {
- update();
- auto entry = Git::treeEntryByPath(tree, path);
+ return getattr(Git::treeEntryByPath(tree, path).get());
+}
+
+NetFS::Attr
+GitFS::Repo::getattr(const git_tree_entry * entry) const
+{
+ if (S_ISREG(git_tree_entry_filemode(entry))) {
+ return getattr(entry, Git::blobLookup(repo, *git_tree_entry_id(entry)).get());
+ }
+ return getattr(entry, nullptr);
+}
+
+NetFS::Attr
+GitFS::Repo::getattr(const git_tree_entry * entry, const git_blob * blob) const
+{
+ NetFS::Attr attr {};
+ if (entry) {
attr << *entry;
- if (S_ISREG(git_tree_entry_filemode(entry.get()))) {
- auto blob = Git::blobLookup(repo, *git_tree_entry_id(entry.get()));
+ if (blob) {
attr << *blob;
}
}
diff --git a/src/repo.h b/src/repo.h
index 0087a3f..facf42e 100644
--- a/src/repo.h
+++ b/src/repo.h
@@ -30,6 +30,8 @@ namespace GitFS {
VFS statfs(ReqEnv env, ::std::string path, const ::Ice::Current & ice) override;
int access(ReqEnv env, ::std::string path, int mode, const ::Ice::Current & ice) override;
Attr getattr(ReqEnv env, ::std::string path, const ::Ice::Current & ice) override;
+ [[nodiscard]] Attr getattr(const git_tree_entry *) const;
+ [[nodiscard]] Attr getattr(const git_tree_entry *, const git_blob *) const;
::std::string readlink(ReqEnv env, ::std::string path, const ::Ice::Current & ice) override;
FilePrxPtr open(ReqEnv env, ::std::string path, int flags, const ::Ice::Current & ice) override;
FilePrxPtr create(ReqEnv env, ::std::string path, int flags, int mode, const ::Ice::Current & ice) override;