From 0d97553a5e1d91edfc325f1d9f5cf8c8bdd6a496 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 16 Aug 2025 16:29:06 +0100 Subject: Fix-up all the clang-tidy warnings --- src/blob.cpp | 38 ++++++++++++++-------------- src/blob.h | 21 ++++++++-------- src/dir.cpp | 33 ++++++++++++++----------- src/dir.h | 10 +++++--- src/git.cpp | 56 +++++++++++++++++++++-------------------- src/git.h | 30 +++++++++++----------- src/main.cpp | 5 ++-- src/repo.cpp | 67 ++++++++++++++++++++++++++------------------------ src/repo.h | 46 +++++++++++++++++----------------- src/repoList.cpp | 7 ++++-- src/repoList.h | 8 +++--- unittests/config.cpp | 3 +-- unittests/core.cpp | 27 ++++++++++++++++++-- unittests/mockDefs.cpp | 5 ++-- unittests/mockDefs.h | 5 +++- unittests/service.cpp | 2 +- 16 files changed, 202 insertions(+), 161 deletions(-) diff --git a/src/blob.cpp b/src/blob.cpp index 2211736..285cd0b 100644 --- a/src/blob.cpp +++ b/src/blob.cpp @@ -2,17 +2,16 @@ #include "repo.h" #include #include -#include #include #include #include -#include +#include #include #include -GitFS::Blob::Blob(const Repo * const r, std::string && path) : - repo(r), entry(Git::TreeEntryByPath(repo->tree, path)), blob(getBlob()), blobSize(git_blob_rawsize(blob.get())), - blobContent(static_cast(git_blob_rawcontent(blob.get()))) +GitFS::Blob::Blob(const Repo * const repo, const std::string & path) : + repo(repo), entry(Git::treeEntryByPath(repo->tree, path)), blob(getBlob()), + blobContent(static_cast(git_blob_rawcontent(blob.get())), git_blob_rawsize(blob.get())) { } @@ -28,35 +27,36 @@ GitFS::Blob::getBlob() const throw NetFS::SystemError(ELOOP); } - return Git::BlobLookup(repo->repo, *git_tree_entry_id(entry.get())); + return Git::blobLookup(repo->repo, *git_tree_entry_id(entry.get())); } void -GitFS::Blob::close(const ::Ice::Current & current) +GitFS::Blob::close(const ::Ice::Current & ice) { - current.adapter->remove(current.id); + ice.adapter->remove(ice.id); } NetFS::Attr GitFS::Blob::fgetattr(const ::Ice::Current &) { - NetFS::Attr a; - a << *blob << *entry << *repo->commit; - a.gid = repo->gid; - a.uid = repo->uid; - return a; + NetFS::Attr attr; + attr << *blob << *entry << *repo->commit; + attr.gid = repo->gid; + attr.uid = repo->uid; + return attr; } NetFS::Buffer -GitFS::Blob::read(long long int o, long long int s, const ::Ice::Current &) +GitFS::Blob::read(long long int offsetSized, long long int sizeLong, const ::Ice::Current &) { - const auto offset {static_cast(o)}; - const auto size {static_cast(s)}; - if (offset > blobSize) { + const size_t offset = safe {offsetSized}; + if (offset > blobContent.size()) { return {}; } - auto len = std::min(blobSize - offset, size); - return {blobContent + offset, blobContent + offset + len}; + const size_t size = safe {sizeLong}; + const auto len = std::min(blobContent.size() - offset, size); + const auto range = blobContent.subspan(offset, len); + return {range.begin(), range.end()}; } void diff --git a/src/blob.h b/src/blob.h index 0b2f6e7..3443e5d 100644 --- a/src/blob.h +++ b/src/blob.h @@ -4,8 +4,10 @@ #include "git.h" #include #include +#include #include #include + namespace Ice { struct Current; } @@ -13,27 +15,26 @@ namespace Ice { namespace GitFS { using namespace NetFS; class Repo; + class Blob : public File { public: - Blob(const Repo * const r, std::string &&); + Blob(const Repo * repo, const std::string &); - void close(const ::Ice::Current & current) override; - Attr fgetattr(const ::Ice::Current & current) override; - Buffer read(long long int offset, long long int size, const ::Ice::Current & current) override; - void ftruncate(long long int size, const ::Ice::Current & current) override; + void close(const ::Ice::Current & ice) override; + Attr fgetattr(const ::Ice::Current & ice) override; + Buffer read(long long int offset, long long int size, const ::Ice::Current & ice) override; + void ftruncate(long long int size, const ::Ice::Current & ice) override; void write(long long int offset, long long int size, std::pair data, - const ::Ice::Current & current) override; + const ::Ice::Current & ice) override; long long int copyrange( FilePrxPtr, long long int, long long int, long long int, int, const Ice::Current &) override; private: - Git::BlobPtr getBlob() const; + [[nodiscard]] Git::BlobPtr getBlob() const; const Repo * const repo; Git::TreeEntryPtr entry; Git::BlobPtr blob; - using BlobSize = decltype(git_blob_rawsize({})); - const BlobSize blobSize; - const char * const blobContent; + std::span blobContent; }; } diff --git a/src/dir.cpp b/src/dir.cpp index f502c45..b2de780 100644 --- a/src/dir.cpp +++ b/src/dir.cpp @@ -12,7 +12,8 @@ #include #include -GitFS::Directory::Directory(Repo * const r, std::string && p) : repo(r), path(std::move(p)), subTreeCacheRootId({}) +GitFS::Directory::Directory(Repo * const repo, std::string path) : + repo(repo), path(std::move(path)), subTreeCacheRootId({}) { getSubtree(); } @@ -26,11 +27,11 @@ GitFS::Directory::getSubtree() const subTreeCache = repo->tree; } else { - auto e = Git::TreeEntryByPath(repo->tree, path); - if (!S_ISDIR(git_tree_entry_filemode(e.get()))) { + auto entry = Git::treeEntryByPath(repo->tree, path); + if (!S_ISDIR(git_tree_entry_filemode(entry.get()))) { throw NetFS::SystemError(ENOTDIR); } - subTreeCache = Git::TreeLookup(repo->repo, *git_tree_entry_id(e.get())); + subTreeCache = Git::treeLookup(repo->repo, *git_tree_entry_id(entry.get())); } subTreeCacheRootId = *git_tree_id(repo->tree.get()); } @@ -38,9 +39,9 @@ GitFS::Directory::getSubtree() const } void -GitFS::Directory::close(const ::Ice::Current & current) +GitFS::Directory::close(const ::Ice::Current & ice) { - current.adapter->remove(current.id); + ice.adapter->remove(ice.id); } NetFS::NameList @@ -48,9 +49,11 @@ GitFS::Directory::readdir(const ::Ice::Current &) { const auto subTree = getSubtree(); NetFS::NameList list; - for (auto idx = git_tree_entrycount(subTree.get()); idx--;) { + auto idx = git_tree_entrycount(subTree.get()); + list.reserve(idx); + while (idx--) { const auto entry = git_tree_entry_byindex(subTree.get(), idx); - list.push_back(git_tree_entry_name(entry)); + list.emplace_back(git_tree_entry_name(entry)); } return list; } @@ -62,15 +65,15 @@ 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 a {}; - a << *entry << *repo->commit; + 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)); - a << *blob; + auto blob = Git::blobLookup(repo->repo, *git_tree_entry_id(entry)); + attr << *blob; } - a.gid = repo->gid; - a.uid = repo->uid; - list.emplace(git_tree_entry_name(entry), a); + attr.gid = repo->gid; + attr.uid = repo->uid; + list.emplace(git_tree_entry_name(entry), std::move(attr)); } return list; } diff --git a/src/dir.h b/src/dir.h index 626d80f..1d5ee24 100644 --- a/src/dir.h +++ b/src/dir.h @@ -6,6 +6,7 @@ #include #include #include + namespace Ice { struct Current; } @@ -13,13 +14,14 @@ namespace Ice { namespace GitFS { using namespace NetFS; class Repo; + class Directory : public NetFS::Directory { public: - Directory(Repo * const r, std::string &&); + Directory(Repo * repo, std::string); - void close(const ::Ice::Current & current) override; - NameList readdir(const ::Ice::Current & current) override; - DirectoryContents listdir(const ::Ice::Current & current) override; + void close(const ::Ice::Current & ice) override; + NameList readdir(const ::Ice::Current & ice) override; + DirectoryContents listdir(const ::Ice::Current & ice) override; private: Git::TreePtr getSubtree() const; diff --git a/src/git.cpp b/src/git.cpp index e6aed3f..b242545 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -24,7 +25,7 @@ namespace GitFS::Git { } git_oid - OidParse(const std::string_view & str) + oidParse(const std::string_view str) { git_oid oid; gitSafe(git_oid_fromstrn, &oid, str.data(), str.length()); @@ -32,41 +33,44 @@ namespace GitFS::Git { } RepositoryPtr - RepositoryOpenBare(const std::string & path) + repositoryOpenBare(const std::string & path) { return gitSafeGet(git_repository_open_bare, git_repository_free, path.c_str()); } BlobPtr - BlobLookup(const RepositoryPtr & repo, const git_oid & blob) + blobLookup(const RepositoryPtr & repo, const git_oid & blob) { return gitSafeGet(git_blob_lookup, git_blob_free, repo.get(), &blob); } CommitPtr - CommitLookup(const RepositoryPtr & repo, const git_oid & commitId) + commitLookup(const RepositoryPtr & repo, const git_oid & commitId) { return gitSafeGet(git_commit_lookup, git_commit_free, repo.get(), &commitId); } TreePtr - TreeLookup(const RepositoryPtr & repo, const git_oid & treeId) + treeLookup(const RepositoryPtr & repo, const git_oid & treeId) { return gitSafeGet(git_tree_lookup, git_tree_free, repo.get(), &treeId); } TreeEntryPtr - TreeEntryByPath(const TreePtr & tree, const std::string & path) + treeEntryByPath(const TreePtr & tree, const std::string & path) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) Skip leading / with C interface return gitSafeGet(git_tree_entry_bypath, git_tree_entry_free, tree.get(), path.c_str() + 1); } + RefPtr - Commitish(const RepositoryPtr & repo, const std::string & name) + commitish(const RepositoryPtr & repo, const std::string & name) { return gitSafeGet(git_reference_dwim, git_reference_free, repo.get(), name.c_str()); } + RefPtr - Resolve(const RefPtr & ref) + resolve(const RefPtr & ref) { return gitSafeGet(git_reference_resolve, git_reference_free, ref.get()); } @@ -74,44 +78,44 @@ namespace GitFS::Git { namespace NetFS { Attr & - operator<<(Attr & a, const git_tree_entry & e) + operator<<(Attr & attr, const git_tree_entry & entry) { - a.mode = git_tree_entry_filemode(&e); - if (S_ISDIR(a.mode)) { - a.mode |= S_IXUSR | S_IXGRP | S_IXOTH | S_IRUSR | S_IRGRP | S_IROTH; + attr.mode = git_tree_entry_filemode(&entry); + if (S_ISDIR(attr.mode)) { + attr.mode |= S_IXUSR | S_IXGRP | S_IXOTH | S_IRUSR | S_IRGRP | S_IROTH; } - else if (S_ISLNK(a.mode)) { - a.mode |= S_IRUSR | S_IRGRP | S_IROTH; + else if (S_ISLNK(attr.mode)) { + attr.mode |= S_IRUSR | S_IRGRP | S_IROTH; } else { - a.mode ^= S_IWUSR; + attr.mode ^= S_IWUSR; } - return a; + return attr; } Attr & - operator<<(Attr & a, const git_commit & c) + operator<<(Attr & attr, const git_commit & commit) { - a.ctime = a.atime = a.mtime = git_commit_time(&c); - return a; + attr.ctime = attr.atime = attr.mtime = git_commit_time(&commit); + return attr; } Attr & - operator<<(Attr & a, const git_blob & b) + operator<<(Attr & attr, const git_blob & blob) { - a.blockSize = 1; - a.blocks = a.size = static_cast(git_blob_rawsize(&b)); - return a; + attr.blockSize = 1; + attr.blocks = attr.size = safe {git_blob_rawsize(&blob)}; + return attr; } } namespace std { std::ostream & - operator<<(std::ostream & s, const git_oid & oid) + operator<<(std::ostream & strm, const git_oid & oid) { std::array str {}; git_oid_tostr(str.data(), str.size(), &oid); - s.write(str.data(), GIT_OID_HEXSZ); - return s; + strm.write(str.data(), GIT_OID_HEXSZ); + return strm; } } diff --git a/src/git.h b/src/git.h index 1dce92e..bc82fef 100644 --- a/src/git.h +++ b/src/git.h @@ -12,10 +12,10 @@ namespace GitFS::Git { template void - gitSafe(int (*func)(P...), A... p) + gitSafe(int (*func)(P...), A... params) { - if (int _giterror = func(p...)) { - throwError(_giterror); + if (int giterror = func(params...)) { + throwError(giterror); } } @@ -23,33 +23,33 @@ namespace GitFS::Git { template auto - gitSafeGet(int (*get)(R **, P...), void (*release)(R *), A... p) + gitSafeGet(int (*get)(R **, P...), void (*release)(R *), A... params) { - R * r = nullptr; - gitSafe(get, &r, p...); - return TPtr(r, release); + R * rtn = nullptr; + gitSafe(get, &rtn, params...); + return TPtr(rtn, release); } - git_oid OidParse(const std::string_view & str); + git_oid oidParse(std::string_view str); using RepositoryPtr = TPtr; - RepositoryPtr RepositoryOpenBare(const std::string & path); + RepositoryPtr repositoryOpenBare(const std::string & path); using BlobPtr = TPtr; - BlobPtr BlobLookup(const RepositoryPtr & repo, const git_oid & blob); + BlobPtr blobLookup(const RepositoryPtr & repo, const git_oid & blob); using CommitPtr = TPtr; - CommitPtr CommitLookup(const RepositoryPtr & repo, const git_oid & commitId); + CommitPtr commitLookup(const RepositoryPtr & repo, const git_oid & commitId); using TreePtr = TPtr; - TreePtr TreeLookup(const RepositoryPtr & repo, const git_oid & treeId); + TreePtr treeLookup(const RepositoryPtr & repo, const git_oid & treeId); using TreeEntryPtr = TPtr; - TreeEntryPtr TreeEntryByPath(const TreePtr & tree, const std::string & path); + TreeEntryPtr treeEntryByPath(const TreePtr & tree, const std::string & path); using RefPtr = TPtr; - RefPtr Commitish(const RepositoryPtr & repo, const std::string & name); - RefPtr Resolve(const RefPtr &); + RefPtr commitish(const RepositoryPtr & repo, const std::string & name); + RefPtr resolve(const RefPtr &); } namespace NetFS { diff --git a/src/main.cpp b/src/main.cpp index 7ee7dff..1314d12 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -30,10 +29,10 @@ namespace GitFS { Main & operator=(Main &&) = delete; void - addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, + addObjects(const std::string &, const Ice::CommunicatorPtr & com, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adp) override { - IceTray::Cube::addObject(adp, "Service", ic->getProperties()); + IceTray::Cube::addObject(adp, "Service", com->getProperties()); } }; diff --git a/src/repo.cpp b/src/repo.cpp index 2bced8a..6bf442f 100644 --- a/src/repo.cpp +++ b/src/repo.cpp @@ -15,21 +15,23 @@ #include #include -std::string -operator/(const std::string & a, const std::string & b) -{ - return a.empty() ? b : a; +namespace { + std::string + operator/(const std::string & value, const std::string & fallback) + { + return value.empty() ? fallback : value; + } } GitFS::Repo::Repo(const PropertyReader & properties) : - repo(Git::RepositoryOpenBare(properties("gitdir"))), commitish(properties("commitish") / "main"), isBranch(false), + repo(Git::repositoryOpenBare(properties("gitdir"))), commitish(properties("commitish") / "main"), isBranch(false), resolvedAt(0), gid(properties("gid") / "root"), uid(properties("uid") / "root") { if (commitish.length() == GIT_OID_HEXSZ) { - commit = Git::CommitLookup(repo, Git::OidParse(commitish)); + commit = Git::commitLookup(repo, Git::oidParse(commitish)); } else { - ref = Git::Commitish(repo, commitish); + ref = Git::commitish(repo, commitish); isBranch = git_reference_is_branch(ref.get()); } update(); @@ -38,17 +40,18 @@ GitFS::Repo::Repo(const PropertyReader & properties) : void GitFS::Repo::update() { - if (!commit || (isBranch && ref && resolvedAt < std::time(nullptr) - 30)) { - commit = Git::CommitLookup(repo, *git_reference_target(Git::Resolve(ref).get())); + constexpr time_t MIN_CHECK_TIME = 30; + if (!commit || (isBranch && ref && resolvedAt < std::time(nullptr) - MIN_CHECK_TIME)) { + commit = Git::commitLookup(repo, *git_reference_target(Git::resolve(ref).get())); resolvedAt = std::time(nullptr); } - tree = Git::TreeLookup(repo, *git_commit_tree_id(commit.get())); + tree = Git::treeLookup(repo, *git_commit_tree_id(commit.get())); } void -GitFS::Repo::disconnect(const ::Ice::Current & current) +GitFS::Repo::disconnect(const ::Ice::Current & ice) { - current.adapter->remove(current.id); + ice.adapter->remove(ice.id); } NetFS::DirectoryPrxPtr @@ -73,7 +76,7 @@ GitFS::Repo::statfs(ReqEnv, ::std::string path, const ::Ice::Current &) } int -GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current &) +GitFS::Repo::access(ReqEnv, const ::std::string path, const int mode, const ::Ice::Current &) { if (mode & W_OK) { return EACCES; @@ -87,8 +90,8 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current & try { update(); - auto e = Git::TreeEntryByPath(tree, path); - const auto emode = git_tree_entry_filemode(e.get()); + auto entry = Git::treeEntryByPath(tree, path); + const auto emode = git_tree_entry_filemode(entry.get()); if (S_ISDIR(emode)) { return 0; @@ -111,46 +114,46 @@ GitFS::Repo::access(ReqEnv, ::std::string path, int mode, const ::Ice::Current & } NetFS::Attr -GitFS::Repo::getattr(ReqEnv, ::std::string path, const ::Ice::Current &) +GitFS::Repo::getattr(ReqEnv, const ::std::string path, const ::Ice::Current &) { if (path.empty()) { throw NetFS::SystemError(EINVAL); } - NetFS::Attr a {}; + NetFS::Attr attr {}; if (path == "/") { - a.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; + attr.mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; } else { update(); - auto entry = Git::TreeEntryByPath(tree, path); - a << *entry; + auto entry = Git::treeEntryByPath(tree, path); + attr << *entry; if (S_ISREG(git_tree_entry_filemode(entry.get()))) { - auto blob = Git::BlobLookup(repo, *git_tree_entry_id(entry.get())); - a << *blob; + auto blob = Git::blobLookup(repo, *git_tree_entry_id(entry.get())); + attr << *blob; } } - a << *commit; - a.gid = gid; - a.uid = uid; - return a; + attr << *commit; + attr.gid = gid; + attr.uid = uid; + return attr; } ::std::string -GitFS::Repo::readlink(ReqEnv, ::std::string path, const ::Ice::Current &) +GitFS::Repo::readlink(ReqEnv, const ::std::string path, const ::Ice::Current &) { if (path.empty() || path == "/") { throw NetFS::SystemError(EINVAL); } update(); - auto e = Git::TreeEntryByPath(tree, path); - if (!S_ISLNK(git_tree_entry_filemode(e.get()))) { + auto entry = Git::treeEntryByPath(tree, path); + if (!S_ISLNK(git_tree_entry_filemode(entry.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())}; + auto blob = Git::blobLookup(repo, *git_tree_entry_id(entry.get())); + auto content = static_cast(git_blob_rawcontent(blob.get())); + return {content, git_blob_rawsize(blob.get())}; } NetFS::FilePrxPtr diff --git a/src/repo.h b/src/repo.h index 795dd87..0087a3f 100644 --- a/src/repo.h +++ b/src/repo.h @@ -12,38 +12,40 @@ #include #include #include + namespace Ice { struct Current; } namespace GitFS { using namespace NetFS; - using PropertyReader = std::function; + using PropertyReader = std::function; + class Repo : public Volume { public: - Repo(const PropertyReader &); + explicit Repo(const PropertyReader &); - void disconnect(const ::Ice::Current & current) override; - DirectoryPrxPtr opendir(ReqEnv env, ::std::string path, const ::Ice::Current & current) override; - VFS statfs(ReqEnv env, ::std::string path, const ::Ice::Current & current) override; - int access(ReqEnv env, ::std::string path, int mode, const ::Ice::Current & current) override; - Attr getattr(ReqEnv env, ::std::string path, const ::Ice::Current & current) override; - ::std::string readlink(ReqEnv env, ::std::string path, const ::Ice::Current & current) override; - FilePrxPtr open(ReqEnv env, ::std::string path, int flags, const ::Ice::Current & current) override; - FilePrxPtr create(ReqEnv env, ::std::string path, int flags, int mode, const ::Ice::Current & current) override; - void truncate(ReqEnv env, ::std::string path, long long int size, const ::Ice::Current & current) override; - void unlink(ReqEnv env, ::std::string path, const ::Ice::Current & current) override; - void mkdir(ReqEnv env, ::std::string path, int mode, const ::Ice::Current & current) override; - void rmdir(ReqEnv env, ::std::string path, const ::Ice::Current & current) override; - void mknod(ReqEnv env, ::std::string path, int mode, int dev, const ::Ice::Current & current) override; - void symlink(ReqEnv env, ::std::string path1, ::std::string path2, const ::Ice::Current & current) override; - void link(ReqEnv env, ::std::string path1, ::std::string path2, const ::Ice::Current & current) override; - void rename(ReqEnv env, ::std::string from, ::std::string to, const Ice::optional, - const ::Ice::Current & current) override; - void chmod(ReqEnv env, ::std::string path, int mode, const ::Ice::Current & current) override; - void chown(ReqEnv env, ::std::string path, int uid, int gid, const ::Ice::Current & current) override; + void disconnect(const ::Ice::Current & ice) override; + DirectoryPrxPtr opendir(ReqEnv env, ::std::string path, const ::Ice::Current & ice) override; + 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; + ::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; + void truncate(ReqEnv env, ::std::string path, long long int size, const ::Ice::Current & ice) override; + void unlink(ReqEnv env, ::std::string path, const ::Ice::Current & ice) override; + void mkdir(ReqEnv env, ::std::string path, int mode, const ::Ice::Current & ice) override; + void rmdir(ReqEnv env, ::std::string path, const ::Ice::Current & ice) override; + void mknod(ReqEnv env, ::std::string path, int mode, int dev, const ::Ice::Current & ice) override; + void symlink(ReqEnv env, ::std::string path1, ::std::string path2, const ::Ice::Current & ice) override; + void link(ReqEnv env, ::std::string path1, ::std::string path2, const ::Ice::Current & ice) override; + void rename(ReqEnv env, ::std::string pathFrom, ::std::string pathTo, Ice::optional, + const ::Ice::Current & ice) override; + void chmod(ReqEnv env, ::std::string path, int mode, const ::Ice::Current & ice) override; + void chown(ReqEnv env, ::std::string path, int uid, int gid, const ::Ice::Current & ice) override; void utimens(ReqEnv env, ::std::string path, long long int atime, long long int atimens, long long int mtime, - long long int mtimens, const ::Ice::Current & current) override; + long long int mtimens, const ::Ice::Current & ice) override; private: void update(); diff --git a/src/repoList.cpp b/src/repoList.cpp index 7a69b78..8c5b8a9 100644 --- a/src/repoList.cpp +++ b/src/repoList.cpp @@ -7,11 +7,12 @@ #include #include #include +#include #include #include #include -GitFS::RepoList::RepoList(Ice::PropertiesPtr && p) : properties(std::move(p)) { } +GitFS::RepoList::RepoList(Ice::PropertiesPtr props) : properties(std::move(props)) { } AdHocFormatter(RepoPropertyName, "GitFS.%?.%?"); @@ -38,6 +39,8 @@ GitFS::RepoList::connect(const ::std::string volume, const ::std::string auth, c NetFS::SettingsPtr GitFS::RepoList::getSettings(const ::Ice::Current & ice) { + constexpr int DEFAULT_MAX_MESSAGE_SIZE = 1024; const auto props = ice.adapter->getCommunicator()->getProperties(); - return std::make_shared(props->getPropertyAsIntWithDefault("Ice.MessageSizeMax", 1024)); + return std::make_shared( + props->getPropertyAsIntWithDefault("Ice.MessageSizeMax", DEFAULT_MAX_MESSAGE_SIZE)); } diff --git a/src/repoList.h b/src/repoList.h index 7995136..9dab8b5 100644 --- a/src/repoList.h +++ b/src/repoList.h @@ -5,6 +5,7 @@ #include #include #include + namespace Ice { struct Current; } @@ -12,11 +13,10 @@ namespace Ice { namespace GitFS { class RepoList : public NetFS::Service { public: - RepoList(Ice::PropertiesPtr &&); + explicit RepoList(Ice::PropertiesPtr); - NetFS::VolumePrxPtr connect( - const ::std::string volume, const ::std::string auth, const ::Ice::Current & current) override; - NetFS::SettingsPtr getSettings(const ::Ice::Current & current) override; + NetFS::VolumePrxPtr connect(::std::string volume, ::std::string auth, const ::Ice::Current & ice) override; + NetFS::SettingsPtr getSettings(const ::Ice::Current & ice) override; private: const Ice::PropertiesPtr properties; diff --git a/unittests/config.cpp b/unittests/config.cpp index b84304b..72d7d31 100644 --- a/unittests/config.cpp +++ b/unittests/config.cpp @@ -7,11 +7,10 @@ #include #include #include -#include -#include #include #include #include + namespace NetFS { class ConfigError; } diff --git a/unittests/core.cpp b/unittests/core.cpp index fb2f477..960b491 100644 --- a/unittests/core.cpp +++ b/unittests/core.cpp @@ -125,38 +125,46 @@ BOOST_DATA_TEST_CASE( { BOOST_CHECK_EQUAL(EACCES, v->access(env, path, W_OK)); } + BOOST_DATA_TEST_CASE(accessDirs, DIRPATHS, path) { BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK)); BOOST_CHECK_EQUAL(0, v->access(env, path, X_OK)); } + BOOST_DATA_TEST_CASE(accessRead, REGPATHS, path) { BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK)); BOOST_CHECK_EQUAL(EACCES, v->access(env, path, X_OK)); } + BOOST_DATA_TEST_CASE(accessLink, LINKPATHS, path) { BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK)); BOOST_CHECK_EQUAL(0, v->access(env, path, X_OK)); } + BOOST_DATA_TEST_CASE(accessExec, EXECPATHS, path) { BOOST_CHECK_EQUAL(0, v->access(env, path, R_OK)); BOOST_CHECK_EQUAL(0, v->access(env, path, X_OK)); } + BOOST_DATA_TEST_CASE(accessInval, INVALIDPATHS * btdata::make({R_OK, X_OK}), path, mode) { BOOST_CHECK_EQUAL(EINVAL, v->access(env, path, mode)); } + BOOST_DATA_TEST_CASE(accessBad, BADPATHS * btdata::make({R_OK, X_OK}), path, mode) { BOOST_CHECK_EQUAL(ENOENT, v->access(env, path, mode)); } + BOOST_DATA_TEST_CASE(statInval, INVALIDPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->getattr(env, path), EINVAL); } + BOOST_DATA_TEST_CASE(statBad, BADPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->getattr(env, path), ENOENT); @@ -167,8 +175,8 @@ const auto FILEMODE = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; const auto EXECMODE = FILEMODE | S_IXUSR | S_IXGRP | S_IXOTH; const auto LINKMODE = S_IFLNK | S_IRUSR | S_IRGRP | S_IROTH; const time_t COMMIT_TIME = 1563621030; -const std::string USER = "root"; -const std::string GROUP = "root"; +constexpr std::string USER = "root"; +constexpr std::string GROUP = "root"; BOOST_DATA_TEST_CASE(statDirs, DIRPATHS, path) { @@ -181,6 +189,7 @@ BOOST_DATA_TEST_CASE(statDirs, DIRPATHS, path) BOOST_CHECK_EQUAL(USER, attr.uid); BOOST_CHECK_EQUAL(GROUP, attr.gid); } + BOOST_DATA_TEST_CASE(statFiles, REGPATHS, path) { const auto attr = v->getattr(env, path); @@ -192,6 +201,7 @@ BOOST_DATA_TEST_CASE(statFiles, REGPATHS, path) BOOST_CHECK_EQUAL(USER, attr.uid); BOOST_CHECK_EQUAL(GROUP, attr.gid); } + BOOST_DATA_TEST_CASE(statExecs, EXECPATHS, path) { const auto attr = v->getattr(env, path); @@ -203,6 +213,7 @@ BOOST_DATA_TEST_CASE(statExecs, EXECPATHS, path) BOOST_CHECK_EQUAL(USER, attr.uid); BOOST_CHECK_EQUAL(GROUP, attr.gid); } + BOOST_DATA_TEST_CASE(statSymlink, LINKPATHS, path) { const auto attr = v->getattr(env, path); @@ -219,10 +230,12 @@ BOOST_DATA_TEST_CASE(readlinkInval, INVALIDPATHS + DIRPATHS + REGPATHS + EXECPAT { BOOST_CHECK_THROW_SYSTEMERROR(v->readlink(env, path), EINVAL); } + BOOST_DATA_TEST_CASE(readlinkBad, BADPATHS + MISSINGPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->readlink(env, path), ENOENT); } + BOOST_DATA_TEST_CASE(readlink, LINKPATHS ^ btdata::make({"executable"}), path, target) { BOOST_CHECK_EQUAL(target, v->readlink(env, path)); @@ -232,14 +245,17 @@ BOOST_DATA_TEST_CASE(openDirInval, INVALIDPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->opendir(env, path), EINVAL); } + BOOST_DATA_TEST_CASE(openDirBad, BADPATHS + MISSINGPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->opendir(env, path), ENOENT); } + BOOST_DATA_TEST_CASE(openDirNotDir, REGPATHS + LINKPATHS + EXECPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->opendir(env, path), ENOTDIR); } + const auto DIRCONTENTS = btdata::make>({ {".gitignore", "Jamroot.jam", "src", "unittests"}, {"Jamfile.jam", "blob.cpp", "blob.h", "dir.cpp", "dir.h", "git.cpp", "git.h", "main.cpp", "repo.cpp", "repo.h", @@ -247,6 +263,7 @@ const auto DIRCONTENTS = btdata::make>({ {"Jamfile.jam", "core.cpp", "fixtures", "mockDefs.cpp", "mockDefs.h"}, {"executable", "symlink"}, }); + BOOST_DATA_TEST_CASE(openDirRead, DIRPATHS ^ DIRCONTENTS, path, contents) { auto dir = v->opendir(env, path); @@ -256,6 +273,7 @@ BOOST_DATA_TEST_CASE(openDirRead, DIRPATHS ^ DIRCONTENTS, path, contents) BOOST_CHECK_EQUAL_COLLECTIONS(names.begin(), names.end(), contents.begin(), contents.end()); dir->close(); } + const auto DIRCONTENTMODES = btdata::make>>({ {{".gitignore", FILEMODE}, {"Jamroot.jam", FILEMODE}, {"src", DIRMODE}, {"unittests", DIRMODE}}, {{"Jamfile.jam", FILEMODE}, {"blob.cpp", FILEMODE}, {"blob.h", FILEMODE}, {"dir.cpp", FILEMODE}, @@ -265,6 +283,7 @@ const auto DIRCONTENTMODES = btdata::makeopendir(env, path); @@ -291,18 +310,22 @@ BOOST_DATA_TEST_CASE(openInval, INVALIDPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), EINVAL); } + BOOST_DATA_TEST_CASE(openBad, BADPATHS + MISSINGPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), ENOENT); } + BOOST_DATA_TEST_CASE(openNotFileDir, DIRPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), EISDIR); } + BOOST_DATA_TEST_CASE(openNotFileLink, LINKPATHS, path) { BOOST_CHECK_THROW_SYSTEMERROR(v->open(env, path, O_RDONLY), ELOOP); } + BOOST_DATA_TEST_CASE(openFileROFSOps, REGPATHS + EXECPATHS, path) { auto f = v->open(env, path, O_RDONLY); diff --git a/unittests/mockDefs.cpp b/unittests/mockDefs.cpp index a144575..7856c2d 100644 --- a/unittests/mockDefs.cpp +++ b/unittests/mockDefs.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -24,13 +23,13 @@ GitFS::Test::Service::Service() : GitFS::Test::Client::Client() : s(getProxy("Service")) { BOOST_TEST_REQUIRE(s); - s->ice_ping(); + BOOST_CHECK_NO_THROW(s->ice_ping()); } GitFS::Test::VolumeClient::VolumeClient() : v(s->connect("testrepo", "testauth")) { BOOST_TEST_REQUIRE(v); - v->ice_ping(); + BOOST_CHECK_NO_THROW(v->ice_ping()); } GitFS::Test::VolumeClient::~VolumeClient() diff --git a/unittests/mockDefs.h b/unittests/mockDefs.h index 9efe187..9fa3ab7 100644 --- a/unittests/mockDefs.h +++ b/unittests/mockDefs.h @@ -1,6 +1,7 @@ #ifndef GITFS_TEST_MOCKDEFS_H #define GITFS_TEST_MOCKDEFS_H +#include #include #include #include @@ -19,10 +20,12 @@ namespace GitFS::Test { const NetFS::ServicePrxPtr s; }; + class DLL_PUBLIC VolumeClient : public Client { public: VolumeClient(); - ~VolumeClient(); + ~VolumeClient() override; + SPECIAL_MEMBERS_DELETE(VolumeClient); const NetFS::ReqEnv env; const NetFS::VolumePrxPtr v; diff --git a/unittests/service.cpp b/unittests/service.cpp index e2829a6..f3e7a8c 100644 --- a/unittests/service.cpp +++ b/unittests/service.cpp @@ -7,9 +7,9 @@ #include #include #include -#include #include #include + namespace NetFS { class AuthError; class ConfigError; -- cgit v1.2.3