From db00a9699e3b12e5f1b79b55a4fd35c4e1dee163 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Jul 2019 22:14:31 +0100 Subject: Replace hard-coded test values with properties --- src/Jamfile.jam | 5 ----- src/blob.cpp | 3 ++- src/dir.cpp | 3 ++- src/repo.cpp | 19 ++++++++++++------- src/repo.h | 5 ++++- src/repoList.cpp | 20 +++++++++++++++++--- src/repoList.h | 7 +++++-- 7 files changed, 42 insertions(+), 20 deletions(-) (limited to 'src') 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 : ..//icetray ..//git2 ..//netfs-api -# Testing - ROOT=\"$(gitdir)\" : : ..//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 +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; } diff --git a/src/repo.h b/src/repo.h index 0b8cc56..18b1057 100644 --- a/src/repo.h +++ b/src/repo.h @@ -1,14 +1,16 @@ #ifndef GITFS_REPO_H #define GITFS_REPO_H +#include #include #include "git.h" namespace GitFS { using namespace NetFS; + using PropertyReader = std::function; 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 +#include #include "repoList.h" #include "repo.h" -GitFS::RepoList::RepoList(const Ice::PropertiesPtr &) +#include + +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(ice.adapter->addWithUUID(std::make_shared())); + 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( + ice.adapter->addWithUUID(std::make_shared(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; }; } -- cgit v1.2.3