summaryrefslogtreecommitdiff
path: root/src/repo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo.cpp')
-rw-r--r--src/repo.cpp61
1 files changed, 47 insertions, 14 deletions
diff --git a/src/repo.cpp b/src/repo.cpp
index 4c2a13f..0db5b23 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -9,7 +9,7 @@
GitFS::Repo::Repo() :
repo(Git::RepositoryOpenBare(rootDir)),
- commit(Git::CommitLookup(repo, Git::OidParse("9197cb3c6e58e6f24deb0af326f695aac87bc36d"))),
+ commit(Git::CommitLookup(repo, Git::OidParse("7a0ccb40084c3ab31d9856e7f689c0514c28c930"))),
tree(Git::TreeLookup(repo, *git_commit_tree_id(commit.get())))
{
}
@@ -24,14 +24,18 @@ GitFS::Repo::disconnect(const ::Ice::Current& current)
NetFS::DirectoryPrxPtr
GitFS::Repo::opendir(ReqEnv, ::std::string path, const ::Ice::Current& ice)
{
+ if (path.empty()) throw NetFS::SystemError(EINVAL);
+
return Ice::uncheckedCast<NetFS::DirectoryV2Prx>(ice.adapter->addWithUUID(
- std::make_shared<Directory>(tree, path)));
+ std::make_shared<Directory>(this, path)));
}
NetFS::VFS
-GitFS::Repo::statfs(ReqEnv, ::std::string, const ::Ice::Current&)
+GitFS::Repo::statfs(ReqEnv, ::std::string path, const ::Ice::Current&)
{
+ if (path.empty()) throw NetFS::SystemError(EINVAL);
+
return {};
}
@@ -48,6 +52,7 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&)
const auto emode = git_tree_entry_filemode(e.get());
if (S_ISDIR(emode)) return 0;
+ if (S_ISLNK(emode)) return 0;
if (mode & R_OK && !(S_IRUSR & emode)) return EACCES;
if (mode & X_OK && !(S_IXUSR & emode)) return EACCES;
@@ -57,7 +62,7 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&)
if (e.err == GIT_ENOTFOUND) {
return ENOENT;
}
- throw NetFS::SystemError(EIO);
+ Git::ErrorToSystemError(e);
}
}
@@ -65,29 +70,57 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&)
NetFS::Attr
GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current&)
{
- NetFS::Attr a {};
- (void)path;
- a.ctime = a.atime = a.mtime = git_commit_time(commit.get());
- return a;
+ if (path.empty()) throw NetFS::SystemError(EINVAL);
+
+ try {
+ NetFS::Attr a {};
+ if (path == "/") {
+ a.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
+ }
+ else {
+ auto entry = Git::TreeEntryByPath(tree, path);
+ a << *entry;
+ if (S_ISREG(git_tree_entry_filemode(entry.get()))) {
+ auto blob = Git::BlobLookup(repo, *git_tree_entry_id(entry.get()));
+ a << *blob;
+ }
+ }
+ a << *commit;
+ a.gid = a.uid = "root";
+ return a;
+ }
+ catch (const Git::Error & e) {
+ Git::ErrorToSystemError(e);
+ }
}
::std::string
GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current&)
{
- auto e = Git::TreeEntryByPath(tree, path);
- if (!e) throw NetFS::SystemError(ENOENT);
- const auto emode = git_tree_entry_filemode(e.get());
- if (!S_ISLNK(emode)) throw NetFS::SystemError(EINVAL);
- return {};
+ if (path.empty() || path == "/") throw NetFS::SystemError(EINVAL);
+
+ try {
+ auto e = Git::TreeEntryByPath(tree, path);
+ if (!S_ISLNK(git_tree_entry_filemode(e.get()))) throw NetFS::SystemError(EINVAL);
+ auto blob = Git::BlobLookup(repo, *git_tree_entry_id(e.get()));
+ auto n = static_cast<const ::std::string::value_type *>(git_blob_rawcontent(blob.get()));
+ return { n, n + git_blob_rawsize(blob.get()) };
+ }
+ catch (const Git::Error & e) {
+ Git::ErrorToSystemError(e);
+ }
}
NetFS::FilePrxPtr
GitFS::Repo::open(ReqEnv, ::std::string path, int, const ::Ice::Current& ice)
{
+ if (path.empty()) throw NetFS::SystemError(EINVAL);
+ if (path == "/") throw NetFS::SystemError(EISDIR);
+
return Ice::uncheckedCast<NetFS::FilePrx>(ice.adapter->addWithUUID(
- std::make_shared<Blob>(repo, Git::TreeEntryByPath(tree, path))));
+ std::make_shared<Blob>(this, path)));
}