storage/local: remove utf8 path from constructor

Build the UTF-8 version of the path automatically in the constructor.
This commit is contained in:
Max Kellermann 2014-02-07 23:41:06 +01:00
parent b0b086d473
commit be081929f4
4 changed files with 14 additions and 13 deletions

View File

@ -162,10 +162,7 @@ InitStorage(Error &error)
path_fs.ChopSeparators(); path_fs.ChopSeparators();
CheckDirectoryReadable(path_fs); CheckDirectoryReadable(path_fs);
const auto utf8 = path_fs.ToUTF8(); instance->storage = CreateLocalStorage(path_fs);
assert(!utf8.empty());
instance->storage = CreateLocalStorage(utf8.c_str(), path_fs);
return true; return true;
} }

View File

@ -50,12 +50,15 @@ public:
}; };
class LocalStorage final : public Storage { class LocalStorage final : public Storage {
const std::string base_utf8;
const AllocatedPath base_fs; const AllocatedPath base_fs;
const std::string base_utf8;
public: public:
LocalStorage(const char *_base_utf8, Path _base_fs) explicit LocalStorage(Path _base_fs)
:base_utf8(_base_utf8), base_fs(_base_fs) {} :base_fs(_base_fs), base_utf8(base_fs.ToUTF8()) {
assert(!base_fs.IsNull());
assert(!base_utf8.empty());
}
/* virtual methods from class Storage */ /* virtual methods from class Storage */
virtual bool GetInfo(const char *uri_utf8, bool follow, FileInfo &info, virtual bool GetInfo(const char *uri_utf8, bool follow, FileInfo &info,
@ -203,7 +206,7 @@ LocalDirectoryReader::GetInfo(bool follow, FileInfo &info, Error &error)
} }
Storage * Storage *
CreateLocalStorage(const char *base_utf8, Path base_fs) CreateLocalStorage(Path base_fs)
{ {
return new LocalStorage(base_utf8, base_fs); return new LocalStorage(base_fs);
} }

View File

@ -28,6 +28,6 @@ class Path;
gcc_malloc gcc_nonnull_all gcc_malloc gcc_nonnull_all
Storage * Storage *
CreateLocalStorage(const char *base_utf8, Path base_fs); CreateLocalStorage(Path base_fs);
#endif #endif

View File

@ -38,9 +38,8 @@ uri_supported_scheme(const char *uri)
return memcmp(uri, "http://", 7) == 0; return memcmp(uri, "http://", 7) == 0;
} }
const char *const music_directory = "/music"; static const char *const music_directory = "/music";
static Storage *const storage = CreateLocalStorage(music_directory, static Storage *storage;
Path::FromFS(music_directory));
static void static void
BuildTag(gcc_unused TagBuilder &tag) BuildTag(gcc_unused TagBuilder &tag)
@ -308,6 +307,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TranslateSongTest);
int int
main(gcc_unused int argc, gcc_unused char **argv) main(gcc_unused int argc, gcc_unused char **argv)
{ {
storage = CreateLocalStorage(Path::FromFS(music_directory));
CppUnit::TextUi::TestRunner runner; CppUnit::TextUi::TestRunner runner;
auto &registry = CppUnit::TestFactoryRegistry::getRegistry(); auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest()); runner.addTest(registry.makeTest());