archive/Lookup: move to fs/LookupFile.cxx
This can be used for other purposes as well.
This commit is contained in:
parent
fcf6415963
commit
bd6b7aa88e
@ -18,7 +18,6 @@ endif
|
|||||||
|
|
||||||
archive_glue = static_library(
|
archive_glue = static_library(
|
||||||
'archive_glue',
|
'archive_glue',
|
||||||
'ArchiveLookup.cxx',
|
|
||||||
'ArchivePlugin.cxx',
|
'ArchivePlugin.cxx',
|
||||||
'../input/plugins/ArchiveInputPlugin.cxx',
|
'../input/plugins/ArchiveInputPlugin.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ArchiveLookup.hxx"
|
#include "LookupFile.hxx"
|
||||||
#include "fs/FileInfo.hxx"
|
#include "FileInfo.hxx"
|
||||||
#include "system/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
@ -33,7 +33,7 @@ FindSlash(PathTraitsFS::pointer_type p, size_t i) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArchiveLookupResult
|
ArchiveLookupResult
|
||||||
archive_lookup(Path pathname)
|
LookupFile(Path pathname)
|
||||||
{
|
{
|
||||||
PathTraitsFS::string buffer(pathname.c_str());
|
PathTraitsFS::string buffer(pathname.c_str());
|
||||||
size_t idx = buffer.size();
|
size_t idx = buffer.size();
|
@ -17,10 +17,10 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_ARCHIVE_LOOKUP_HXX
|
#ifndef MPD_LOOKUP_FILE_HXX
|
||||||
#define MPD_ARCHIVE_LOOKUP_HXX
|
#define MPD_LOOKUP_FILE_HXX
|
||||||
|
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "AllocatedPath.hxx"
|
||||||
|
|
||||||
struct ArchiveLookupResult {
|
struct ArchiveLookupResult {
|
||||||
AllocatedPath archive = nullptr;
|
AllocatedPath archive = nullptr;
|
||||||
@ -50,7 +50,7 @@ struct ArchiveLookupResult {
|
|||||||
* Throws on error.
|
* Throws on error.
|
||||||
*/
|
*/
|
||||||
ArchiveLookupResult
|
ArchiveLookupResult
|
||||||
archive_lookup(Path pathname);
|
LookupFile(Path pathname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -10,6 +10,7 @@ fs_sources = [
|
|||||||
'List.cxx',
|
'List.cxx',
|
||||||
'StandardDirectory.cxx',
|
'StandardDirectory.cxx',
|
||||||
'CheckFile.cxx',
|
'CheckFile.cxx',
|
||||||
|
'LookupFile.cxx',
|
||||||
'DirectoryReader.cxx',
|
'DirectoryReader.cxx',
|
||||||
'io/PeekReader.cxx',
|
'io/PeekReader.cxx',
|
||||||
'io/FileReader.cxx',
|
'io/FileReader.cxx',
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ArchiveInputPlugin.hxx"
|
#include "ArchiveInputPlugin.hxx"
|
||||||
#include "archive/ArchiveLookup.hxx"
|
|
||||||
#include "archive/ArchiveList.hxx"
|
#include "archive/ArchiveList.hxx"
|
||||||
#include "archive/ArchivePlugin.hxx"
|
#include "archive/ArchivePlugin.hxx"
|
||||||
#include "archive/ArchiveFile.hxx"
|
#include "archive/ArchiveFile.hxx"
|
||||||
#include "../InputStream.hxx"
|
#include "../InputStream.hxx"
|
||||||
|
#include "fs/LookupFile.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
@ -31,10 +31,9 @@ OpenArchiveInputStream(Path path, Mutex &mutex)
|
|||||||
{
|
{
|
||||||
const ArchivePlugin *arplug;
|
const ArchivePlugin *arplug;
|
||||||
|
|
||||||
// archive_lookup will modify pname when true is returned
|
|
||||||
ArchiveLookupResult l;
|
ArchiveLookupResult l;
|
||||||
try {
|
try {
|
||||||
l = archive_lookup(path);
|
l = LookupFile(path);
|
||||||
if (l.archive.IsNull()) {
|
if (l.archive.IsNull()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
30
test/TestLookupFile.cxx
Normal file
30
test/TestLookupFile.cxx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "fs/LookupFile.hxx"
|
||||||
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
TEST(ArchiveTest, Lookup)
|
||||||
|
{
|
||||||
|
EXPECT_THROW(LookupFile(Path::FromFS("")), std::system_error);
|
||||||
|
|
||||||
|
EXPECT_FALSE(LookupFile(Path::FromFS(".")));
|
||||||
|
|
||||||
|
EXPECT_FALSE(LookupFile(Path::FromFS("config.h")));
|
||||||
|
|
||||||
|
EXPECT_THROW(LookupFile(Path::FromFS("src/foo/bar")), std::system_error);
|
||||||
|
|
||||||
|
fclose(fopen("dummy", "w"));
|
||||||
|
|
||||||
|
auto result = LookupFile(Path::FromFS("dummy/foo/bar"));
|
||||||
|
EXPECT_TRUE(result);
|
||||||
|
EXPECT_STREQ(result.archive.c_str(), "dummy");
|
||||||
|
EXPECT_STREQ(result.inside.c_str(), "foo/bar");
|
||||||
|
|
||||||
|
result = LookupFile(Path::FromFS("config.h/foo/bar"));
|
||||||
|
EXPECT_TRUE(result);
|
||||||
|
EXPECT_STREQ(result.archive.c_str(), "config.h");
|
||||||
|
EXPECT_STREQ(result.inside.c_str(), "foo/bar");
|
||||||
|
}
|
@ -92,6 +92,9 @@ test('test_queue_priority', executable(
|
|||||||
test('TestFs', executable(
|
test('TestFs', executable(
|
||||||
'TestFs',
|
'TestFs',
|
||||||
'TestFs.cxx',
|
'TestFs.cxx',
|
||||||
|
'TestLookupFile.cxx',
|
||||||
|
'../src/Log.cxx',
|
||||||
|
'../src/LogBackend.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
fs_dep,
|
fs_dep,
|
||||||
@ -339,18 +342,6 @@ endif
|
|||||||
#
|
#
|
||||||
|
|
||||||
if archive_glue_dep.found()
|
if archive_glue_dep.found()
|
||||||
test('test_archive', executable(
|
|
||||||
'test_archive',
|
|
||||||
'test_archive.cxx',
|
|
||||||
'../src/Log.cxx',
|
|
||||||
'../src/LogBackend.cxx',
|
|
||||||
include_directories: inc,
|
|
||||||
dependencies: [
|
|
||||||
archive_glue_dep,
|
|
||||||
gtest_dep,
|
|
||||||
],
|
|
||||||
))
|
|
||||||
|
|
||||||
executable(
|
executable(
|
||||||
'visit_archive',
|
'visit_archive',
|
||||||
'visit_archive.cxx',
|
'visit_archive.cxx',
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
#include "archive/ArchiveLookup.hxx"
|
|
||||||
#include "util/Compiler.h"
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
TEST(ArchiveTest, Lookup)
|
|
||||||
{
|
|
||||||
EXPECT_THROW(archive_lookup(Path::FromFS("")), std::system_error);
|
|
||||||
|
|
||||||
EXPECT_FALSE(archive_lookup(Path::FromFS(".")));
|
|
||||||
|
|
||||||
EXPECT_FALSE(archive_lookup(Path::FromFS("config.h")));
|
|
||||||
|
|
||||||
EXPECT_THROW(archive_lookup(Path::FromFS("src/foo/bar")), std::system_error);
|
|
||||||
|
|
||||||
fclose(fopen("dummy", "w"));
|
|
||||||
|
|
||||||
auto result = archive_lookup(Path::FromFS("dummy/foo/bar"));
|
|
||||||
EXPECT_TRUE(result);
|
|
||||||
EXPECT_STREQ(result.archive.c_str(), "dummy");
|
|
||||||
EXPECT_STREQ(result.inside.c_str(), "foo/bar");
|
|
||||||
|
|
||||||
result = archive_lookup(Path::FromFS("config.h/foo/bar"));
|
|
||||||
EXPECT_TRUE(result);
|
|
||||||
EXPECT_STREQ(result.archive.c_str(), "config.h");
|
|
||||||
EXPECT_STREQ(result.inside.c_str(), "foo/bar");
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user