archive/Lookup: pass class Path

This commit is contained in:
Max Kellermann 2019-06-15 14:06:50 +02:00
parent be79b44dc8
commit fcf6415963
4 changed files with 10 additions and 12 deletions

View File

@ -21,8 +21,6 @@
#include "fs/FileInfo.hxx" #include "fs/FileInfo.hxx"
#include "system/Error.hxx" #include "system/Error.hxx"
#include <string.h>
gcc_pure gcc_pure
static PathTraitsFS::pointer_type static PathTraitsFS::pointer_type
FindSlash(PathTraitsFS::pointer_type p, size_t i) noexcept FindSlash(PathTraitsFS::pointer_type p, size_t i) noexcept
@ -35,9 +33,9 @@ FindSlash(PathTraitsFS::pointer_type p, size_t i) noexcept
} }
ArchiveLookupResult ArchiveLookupResult
archive_lookup(PathTraitsFS::const_pointer_type pathname) archive_lookup(Path pathname)
{ {
PathTraitsFS::string buffer(pathname); PathTraitsFS::string buffer(pathname.c_str());
size_t idx = buffer.size(); size_t idx = buffer.size();
PathTraitsFS::pointer_type slash = nullptr; PathTraitsFS::pointer_type slash = nullptr;

View File

@ -50,7 +50,7 @@ struct ArchiveLookupResult {
* Throws on error. * Throws on error.
*/ */
ArchiveLookupResult ArchiveLookupResult
archive_lookup(PathTraitsFS::const_pointer_type pathname); archive_lookup(Path pathname);
#endif #endif

View File

@ -34,7 +34,7 @@ OpenArchiveInputStream(Path path, Mutex &mutex)
// archive_lookup will modify pname when true is returned // archive_lookup will modify pname when true is returned
ArchiveLookupResult l; ArchiveLookupResult l;
try { try {
l = archive_lookup(path.c_str()); l = archive_lookup(path);
if (l.archive.IsNull()) { if (l.archive.IsNull()) {
return nullptr; return nullptr;
} }

View File

@ -8,22 +8,22 @@
TEST(ArchiveTest, Lookup) TEST(ArchiveTest, Lookup)
{ {
EXPECT_THROW(archive_lookup(""), std::system_error); EXPECT_THROW(archive_lookup(Path::FromFS("")), std::system_error);
EXPECT_FALSE(archive_lookup(".")); EXPECT_FALSE(archive_lookup(Path::FromFS(".")));
EXPECT_FALSE(archive_lookup("config.h")); EXPECT_FALSE(archive_lookup(Path::FromFS("config.h")));
EXPECT_THROW(archive_lookup("src/foo/bar"), std::system_error); EXPECT_THROW(archive_lookup(Path::FromFS("src/foo/bar")), std::system_error);
fclose(fopen("dummy", "w")); fclose(fopen("dummy", "w"));
auto result = archive_lookup("dummy/foo/bar"); auto result = archive_lookup(Path::FromFS("dummy/foo/bar"));
EXPECT_TRUE(result); EXPECT_TRUE(result);
EXPECT_STREQ(result.archive.c_str(), "dummy"); EXPECT_STREQ(result.archive.c_str(), "dummy");
EXPECT_STREQ(result.inside.c_str(), "foo/bar"); EXPECT_STREQ(result.inside.c_str(), "foo/bar");
result = archive_lookup("config.h/foo/bar"); result = archive_lookup(Path::FromFS("config.h/foo/bar"));
EXPECT_TRUE(result); EXPECT_TRUE(result);
EXPECT_STREQ(result.archive.c_str(), "config.h"); EXPECT_STREQ(result.archive.c_str(), "config.h");
EXPECT_STREQ(result.inside.c_str(), "foo/bar"); EXPECT_STREQ(result.inside.c_str(), "foo/bar");