diff --git a/meson.build b/meson.build index 92d25d931..0f955e832 100644 --- a/meson.build +++ b/meson.build @@ -428,7 +428,6 @@ subdir('src/lib/crypto') subdir('src/zeroconf') -subdir('src/fs/io') subdir('src/fs/glue') subdir('src/config') subdir('src/tag') diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx index 2af20e03a..a306b16ab 100644 --- a/src/PlaylistFile.cxx +++ b/src/PlaylistFile.cxx @@ -11,7 +11,7 @@ #include "SongLoader.hxx" #include "Mapper.hxx" #include "protocol/RangeArg.hxx" -#include "fs/io/TextFile.hxx" +#include "io/FileLineReader.hxx" #include "io/FileOutputStream.hxx" #include "io/BufferedOutputStream.hxx" #include "config/Data.hxx" @@ -184,7 +184,7 @@ try { assert(!path_fs.IsNull()); - TextFile file(path_fs); + FileLineReader file{path_fs}; char *s; while ((s = file.ReadLine()) != nullptr) { diff --git a/src/StateFile.cxx b/src/StateFile.cxx index ba5ef0855..398e7f084 100644 --- a/src/StateFile.cxx +++ b/src/StateFile.cxx @@ -5,7 +5,7 @@ #include "StateFile.hxx" #include "output/State.hxx" #include "queue/PlaylistState.hxx" -#include "fs/io/TextFile.hxx" +#include "io/FileLineReader.hxx" #include "io/FileOutputStream.hxx" #include "io/BufferedOutputStream.hxx" #include "storage/StorageState.hxx" @@ -97,7 +97,7 @@ try { FmtDebug(state_file_domain, "Loading state file {}", path_utf8); - TextFile file(config.path); + FileLineReader file{config.path}; #ifdef ENABLE_DATABASE const SongLoader song_loader(partition.instance.GetDatabase(), diff --git a/src/db/plugins/meson.build b/src/db/plugins/meson.build index ae0009332..c3e44fd0f 100644 --- a/src/db/plugins/meson.build +++ b/src/db/plugins/meson.build @@ -38,6 +38,7 @@ db_plugins = static_library( pcre_dep, libmpdclient_dep, log_dep, + zlib_dep, ], ) diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 55f406d91..854861a59 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -18,7 +18,7 @@ #include "db/DatabaseLock.hxx" #include "db/DatabaseError.hxx" #include "lib/fmt/PathFormatter.hxx" -#include "fs/io/TextFile.hxx" +#include "lib/zlib/AutoGunzipFileLineReader.hxx" #include "io/BufferedOutputStream.hxx" #include "io/FileOutputStream.hxx" #include "fs/FileInfo.hxx" @@ -132,7 +132,7 @@ SimpleDatabase::Load() assert(!path.IsNull()); assert(root != nullptr); - TextFile file(path); + AutoGunzipFileLineReader file{path}; LogDebug(simple_db_domain, "reading DB"); diff --git a/src/fs/glue/StandardDirectory.cxx b/src/fs/glue/StandardDirectory.cxx index be295df75..c47bd4084 100644 --- a/src/fs/glue/StandardDirectory.cxx +++ b/src/fs/glue/StandardDirectory.cxx @@ -26,7 +26,8 @@ #include "util/StringSplit.hxx" #include "util/StringStrip.hxx" #include "util/StringCompare.hxx" -#include "fs/io/TextFile.hxx" +#include "io/FileLineReader.hxx" + #include #include #endif @@ -230,7 +231,7 @@ try { if (config_dir.IsNull()) return result; - TextFile input(config_dir / Path::FromFS("user-dirs.dirs")); + FileLineReader input{config_dir / Path::FromFS("user-dirs.dirs")}; char *line; while ((line = input.ReadLine()) != nullptr) if (ParseConfigLine(line, name, result)) diff --git a/src/fs/glue/meson.build b/src/fs/glue/meson.build index a4d24bc20..6b49e816c 100644 --- a/src/fs/glue/meson.build +++ b/src/fs/glue/meson.build @@ -5,7 +5,7 @@ fs_glue = static_library( include_directories: inc, dependencies: [ fs_dep, - fs_io_dep, + io_dep, fmt_dep, log_dep, util_dep, diff --git a/src/fs/io/meson.build b/src/fs/io/meson.build deleted file mode 100644 index 65c8abfb8..000000000 --- a/src/fs/io/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -fs_io = static_library( - 'fs_io', - 'TextFile.cxx', - include_directories: inc, - dependencies: [ - fs_dep, - io_fs_dep, - system_dep, - zlib_dep, - ], -) - -fs_io_dep = declare_dependency( - link_with: fs_io, - dependencies: [ - io_dep, - ], -) diff --git a/src/io/FileLineReader.hxx b/src/io/FileLineReader.hxx new file mode 100644 index 000000000..948b13197 --- /dev/null +++ b/src/io/FileLineReader.hxx @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Copyright The Music Player Daemon Project + +#pragma once + +#include "LineReader.hxx" +#include "FileReader.hxx" +#include "BufferedReader.hxx" + +class FileLineReader final : public LineReader { + FileReader file_reader; + BufferedReader buffered_reader; + +public: + explicit FileLineReader(Path path_fs) + :file_reader(path_fs), + buffered_reader(file_reader) {} + + /* virtual methods from class LineReader */ + char *ReadLine() override { + return buffered_reader.ReadLine(); + } +}; diff --git a/src/fs/io/TextFile.cxx b/src/lib/zlib/AutoGunzipFileLineReader.cxx similarity index 74% rename from src/fs/io/TextFile.cxx rename to src/lib/zlib/AutoGunzipFileLineReader.cxx index 11fbe36ad..05f173682 100644 --- a/src/fs/io/TextFile.cxx +++ b/src/lib/zlib/AutoGunzipFileLineReader.cxx @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#include "TextFile.hxx" +#include "AutoGunzipFileLineReader.hxx" #include "io/FileReader.hxx" #include "io/BufferedReader.hxx" #include "lib/zlib/AutoGunzipReader.hxx" @@ -9,7 +9,7 @@ #include -TextFile::TextFile(Path path_fs) +AutoGunzipFileLineReader::AutoGunzipFileLineReader(Path path_fs) :file_reader(std::make_unique(path_fs)), #ifdef ENABLE_ZLIB gunzip_reader(std::make_unique(*file_reader)), @@ -24,10 +24,10 @@ TextFile::TextFile(Path path_fs) { } -TextFile::~TextFile() noexcept = default; +AutoGunzipFileLineReader::~AutoGunzipFileLineReader() noexcept = default; char * -TextFile::ReadLine() +AutoGunzipFileLineReader::ReadLine() { assert(buffered_reader != nullptr); diff --git a/src/fs/io/TextFile.hxx b/src/lib/zlib/AutoGunzipFileLineReader.hxx similarity index 61% rename from src/fs/io/TextFile.hxx rename to src/lib/zlib/AutoGunzipFileLineReader.hxx index 7051f57ac..8b070ea17 100644 --- a/src/fs/io/TextFile.hxx +++ b/src/lib/zlib/AutoGunzipFileLineReader.hxx @@ -1,11 +1,13 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_TEXT_FILE_HXX -#define MPD_TEXT_FILE_HXX +#pragma once + +#include "config.h" + +#ifdef ENABLE_ZLIB #include "io/LineReader.hxx" -#include "config.h" #include @@ -14,24 +16,28 @@ class FileReader; class AutoGunzipReader; class BufferedReader; -class TextFile final : public LineReader { +class AutoGunzipFileLineReader final : public LineReader { const std::unique_ptr file_reader; -#ifdef ENABLE_ZLIB const std::unique_ptr gunzip_reader; -#endif const std::unique_ptr buffered_reader; public: - explicit TextFile(Path path_fs); + explicit AutoGunzipFileLineReader(Path path_fs); - TextFile(const TextFile &other) = delete; + AutoGunzipFileLineReader(const AutoGunzipFileLineReader &other) = delete; - ~TextFile() noexcept; + ~AutoGunzipFileLineReader() noexcept; /* virtual methods from class LineReader */ char *ReadLine() override; }; +#else + +#include "io/FileLineReader.hxx" + +using AutoGunzipFileLineReader = FileLineReader; + #endif diff --git a/src/lib/zlib/meson.build b/src/lib/zlib/meson.build index a9674e72a..6ca5645e2 100644 --- a/src/lib/zlib/meson.build +++ b/src/lib/zlib/meson.build @@ -10,6 +10,7 @@ zlib = static_library( 'GunzipReader.cxx', 'GzipOutputStream.cxx', 'AutoGunzipReader.cxx', + 'AutoGunzipFileLineReader.cxx', include_directories: inc, dependencies: [ zlib_dep, diff --git a/test/LoadDatabase.cxx b/test/LoadDatabase.cxx index ce5436b5c..7e62890ea 100644 --- a/test/LoadDatabase.cxx +++ b/test/LoadDatabase.cxx @@ -4,9 +4,9 @@ #include "config.h" #include "db/plugins/simple/DatabaseSave.hxx" #include "db/plugins/simple/Directory.hxx" +#include "lib/zlib/AutoGunzipFileLineReader.hxx" #include "fs/Path.hxx" #include "fs/NarrowPath.hxx" -#include "fs/io/TextFile.hxx" #include "util/PrintException.hxx" int @@ -20,7 +20,7 @@ try { const FromNarrowPath db_path = argv[1]; Directory root{{}, nullptr}; - TextFile line_reader{db_path}; + AutoGunzipFileLineReader line_reader{db_path}; db_load_internal(line_reader, root, true); return EXIT_SUCCESS; diff --git a/test/meson.build b/test/meson.build index 99bf19b53..80d848c2a 100644 --- a/test/meson.build +++ b/test/meson.build @@ -252,6 +252,7 @@ if enable_database pcm_basic_dep, song_dep, db_plugins_dep, + zlib_dep, ], )