diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-22 22:14:31 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2019-07-22 22:14:31 +0100 |
commit | db00a9699e3b12e5f1b79b55a4fd35c4e1dee163 (patch) | |
tree | 1b706ea330f7399f7c0c5cb4dc43b5f7f7ba4815 /src | |
parent | Unline git helpers and throw NetFS exceptions (diff) | |
download | netfs-gitfs-db00a9699e3b12e5f1b79b55a4fd35c4e1dee163.tar.bz2 netfs-gitfs-db00a9699e3b12e5f1b79b55a4fd35c4e1dee163.tar.xz netfs-gitfs-db00a9699e3b12e5f1b79b55a4fd35c4e1dee163.zip |
Replace hard-coded test values with properties
Diffstat (limited to 'src')
-rw-r--r-- | src/Jamfile.jam | 5 | ||||
-rw-r--r-- | src/blob.cpp | 3 | ||||
-rw-r--r-- | src/dir.cpp | 3 | ||||
-rw-r--r-- | src/repo.cpp | 19 | ||||
-rw-r--r-- | src/repo.h | 5 | ||||
-rw-r--r-- | src/repoList.cpp | 20 | ||||
-rw-r--r-- | src/repoList.h | 7 |
7 files changed, 42 insertions, 20 deletions
diff --git a/src/Jamfile.jam b/src/Jamfile.jam index d342134..afe5dc7 100644 --- a/src/Jamfile.jam +++ b/src/Jamfile.jam @@ -1,6 +1,3 @@ -# Testing -path-constant gitdir : ../.git ; - lib gitfs++11 : [ glob *.cpp ] : @@ -8,8 +5,6 @@ lib gitfs++11 : <library>..//icetray <library>..//git2 <library>..//netfs-api -# Testing - <define>ROOT=\"$(gitdir)\" : : <library>..//netfs-api ; diff --git a/src/blob.cpp b/src/blob.cpp index a3408b3..ed0e633 100644 --- a/src/blob.cpp +++ b/src/blob.cpp @@ -35,7 +35,8 @@ GitFS::Blob::fgetattr(ReqEnv, const ::Ice::Current&) { NetFS::Attr a; a << *blob << *entry << *repo->commit; - a.gid = a.uid = "root"; + a.gid = repo->gid; + a.uid = repo->uid; return a; } diff --git a/src/dir.cpp b/src/dir.cpp index c590450..98c05cb 100644 --- a/src/dir.cpp +++ b/src/dir.cpp @@ -61,7 +61,8 @@ GitFS::Directory::listdir(const ::Ice::Current&) auto blob = Git::BlobLookup(repo->repo, *git_tree_entry_id(entry)); a << *blob; } - a.gid = a.uid = "root"; + a.gid = repo->gid; + a.uid = repo->uid; list.emplace(git_tree_entry_name(entry), a); } return list; diff --git a/src/repo.cpp b/src/repo.cpp index 32fa401..4059897 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -4,13 +4,17 @@ #include "blob.h" #include "dir.h" -// Testing -#include <definedDirs.h> +std::string operator/(const std::string & a, const std::string & b) +{ + return a.empty() ? b : a; +} -GitFS::Repo::Repo() : - repo(Git::RepositoryOpenBare(rootDir)), - commit(Git::CommitLookup(repo, Git::OidParse("7a0ccb40084c3ab31d9856e7f689c0514c28c930"))), - tree(Git::TreeLookup(repo, *git_commit_tree_id(commit.get()))) +GitFS::Repo::Repo(const PropertyReader & properties) : + repo(Git::RepositoryOpenBare(properties("gitdir"))), + commit(Git::CommitLookup(repo, Git::OidParse(properties("commit")))), + tree(Git::TreeLookup(repo, *git_commit_tree_id(commit.get()))), + gid(properties("gid") / "root"), + uid(properties("uid") / "root") { } @@ -82,7 +86,8 @@ GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current&) } } a << *commit; - a.gid = a.uid = "root"; + a.gid = gid; + a.uid = uid; return a; } @@ -1,14 +1,16 @@ #ifndef GITFS_REPO_H #define GITFS_REPO_H +#include <Ice/Properties.h> #include <volume.h> #include "git.h" namespace GitFS { using namespace NetFS; + using PropertyReader = std::function<std::string(const std::string_view &)>; class Repo : public Volume { public: - Repo(); + Repo(const PropertyReader &); void disconnect(const ::Ice::Current& current) override; DirectoryPrxPtr opendir(ReqEnv env, ::std::string path, const ::Ice::Current& current) override; @@ -36,6 +38,7 @@ namespace GitFS { Git::RepositoryPtr repo; Git::CommitPtr commit; Git::TreePtr tree; + const std::string gid, uid; }; } diff --git a/src/repoList.cpp b/src/repoList.cpp index 51eb6b2..9fc2848 100644 --- a/src/repoList.cpp +++ b/src/repoList.cpp @@ -1,15 +1,29 @@ #include <Ice/ObjectAdapter.h> +#include <Ice/Properties.h> #include "repoList.h" #include "repo.h" -GitFS::RepoList::RepoList(const Ice::PropertiesPtr &) +#include <compileTimeFormatter.h> + +GitFS::RepoList::RepoList(const Ice::PropertiesPtr & p) : properties(p) { } +AdHocFormatter(RepoPropertyName, "GitFS.%?.%?"); + NetFS::VolumePrxPtr -GitFS::RepoList::connect(const ::std::string, const ::std::string, +GitFS::RepoList::connect(const ::std::string volume, const ::std::string auth, const ::Ice::Current & ice) { - return Ice::uncheckedCast<NetFS::VolumePrx>(ice.adapter->addWithUUID(std::make_shared<Repo>())); + if (volume.empty()) throw NetFS::ConfigError(); + + const auto propReader = std::bind(&Ice::Properties::getProperty, properties, + std::bind((std::string(*)(const std::string_view &, const std::string_view &)) + (&RepoPropertyName::get), volume, std::placeholders::_1)); + + if (propReader("gitdir").empty()) throw NetFS::ConfigError(); + if (propReader("authkey") != auth) throw NetFS::AuthError(); + return Ice::uncheckedCast<NetFS::VolumePrx>( + ice.adapter->addWithUUID(std::make_shared<Repo>(propReader))); } diff --git a/src/repoList.h b/src/repoList.h index ac8b885..6929e5b 100644 --- a/src/repoList.h +++ b/src/repoList.h @@ -7,9 +7,12 @@ namespace GitFS { class RepoList : public NetFS::Service { public: - RepoList(const Ice::PropertiesPtr & ptr); + RepoList(const Ice::PropertiesPtr &); - virtual NetFS::VolumePrxPtr connect(const ::std::string volume, const ::std::string auth, const ::Ice::Current& current) override; + NetFS::VolumePrxPtr connect(const ::std::string volume, const ::std::string auth, const ::Ice::Current& current) override; + + private: + const Ice::PropertiesPtr properties; }; } |