fs/io/TextFile: split into class FileLineReader and AutoGunzipFileLineReader
Detangle dependencies.
This commit is contained in:
parent
d888bb1902
commit
08a5768764
|
@ -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')
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -38,6 +38,7 @@ db_plugins = static_library(
|
|||
pcre_dep,
|
||||
libmpdclient_dep,
|
||||
log_dep,
|
||||
zlib_dep,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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 <string.h>
|
||||
#include <utility>
|
||||
#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))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
],
|
||||
)
|
|
@ -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();
|
||||
}
|
||||
};
|
|
@ -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 <cassert>
|
||||
|
||||
TextFile::TextFile(Path path_fs)
|
||||
AutoGunzipFileLineReader::AutoGunzipFileLineReader(Path path_fs)
|
||||
:file_reader(std::make_unique<FileReader>(path_fs)),
|
||||
#ifdef ENABLE_ZLIB
|
||||
gunzip_reader(std::make_unique<AutoGunzipReader>(*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);
|
||||
|
|
@ -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 <memory>
|
||||
|
||||
|
@ -14,24 +16,28 @@ class FileReader;
|
|||
class AutoGunzipReader;
|
||||
class BufferedReader;
|
||||
|
||||
class TextFile final : public LineReader {
|
||||
class AutoGunzipFileLineReader final : public LineReader {
|
||||
const std::unique_ptr<FileReader> file_reader;
|
||||
|
||||
#ifdef ENABLE_ZLIB
|
||||
const std::unique_ptr<AutoGunzipReader> gunzip_reader;
|
||||
#endif
|
||||
|
||||
const std::unique_ptr<BufferedReader> 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
|
|
@ -10,6 +10,7 @@ zlib = static_library(
|
|||
'GunzipReader.cxx',
|
||||
'GzipOutputStream.cxx',
|
||||
'AutoGunzipReader.cxx',
|
||||
'AutoGunzipFileLineReader.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
zlib_dep,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -252,6 +252,7 @@ if enable_database
|
|||
pcm_basic_dep,
|
||||
song_dep,
|
||||
db_plugins_dep,
|
||||
zlib_dep,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue