From 6168d85a886286a43b55a0cd6739a1e1e3987d90 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Jul 2019 20:08:39 +0100 Subject: Unline git helpers and throw NetFS exceptions --- src/repo.cpp | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) (limited to 'src/repo.cpp') diff --git a/src/repo.cpp b/src/repo.cpp index 0db5b23..32fa401 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -58,11 +58,8 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current&) return 0; } - catch (const Git::Error & e) { - if (e.err == GIT_ENOTFOUND) { - return ENOENT; - } - Git::ErrorToSystemError(e); + catch (const NetFS::SystemError & e) { + return e.syserrno; } } @@ -72,26 +69,21 @@ GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current&) { 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; + NetFS::Attr a {}; + if (path == "/") { + a.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; } - catch (const Git::Error & e) { - Git::ErrorToSystemError(e); + 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; } @@ -100,16 +92,11 @@ GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current&) { 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(git_blob_rawcontent(blob.get())); - return { n, n + git_blob_rawsize(blob.get()) }; - } - catch (const Git::Error & e) { - Git::ErrorToSystemError(e); - } + 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(git_blob_rawcontent(blob.get())); + return { n, n + git_blob_rawsize(blob.get()) }; } -- cgit v1.2.3