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/zeroconf')
|
||||||
|
|
||||||
subdir('src/fs/io')
|
|
||||||
subdir('src/fs/glue')
|
subdir('src/fs/glue')
|
||||||
subdir('src/config')
|
subdir('src/config')
|
||||||
subdir('src/tag')
|
subdir('src/tag')
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "SongLoader.hxx"
|
#include "SongLoader.hxx"
|
||||||
#include "Mapper.hxx"
|
#include "Mapper.hxx"
|
||||||
#include "protocol/RangeArg.hxx"
|
#include "protocol/RangeArg.hxx"
|
||||||
#include "fs/io/TextFile.hxx"
|
#include "io/FileLineReader.hxx"
|
||||||
#include "io/FileOutputStream.hxx"
|
#include "io/FileOutputStream.hxx"
|
||||||
#include "io/BufferedOutputStream.hxx"
|
#include "io/BufferedOutputStream.hxx"
|
||||||
#include "config/Data.hxx"
|
#include "config/Data.hxx"
|
||||||
|
@ -184,7 +184,7 @@ try {
|
||||||
|
|
||||||
assert(!path_fs.IsNull());
|
assert(!path_fs.IsNull());
|
||||||
|
|
||||||
TextFile file(path_fs);
|
FileLineReader file{path_fs};
|
||||||
|
|
||||||
char *s;
|
char *s;
|
||||||
while ((s = file.ReadLine()) != nullptr) {
|
while ((s = file.ReadLine()) != nullptr) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "StateFile.hxx"
|
#include "StateFile.hxx"
|
||||||
#include "output/State.hxx"
|
#include "output/State.hxx"
|
||||||
#include "queue/PlaylistState.hxx"
|
#include "queue/PlaylistState.hxx"
|
||||||
#include "fs/io/TextFile.hxx"
|
#include "io/FileLineReader.hxx"
|
||||||
#include "io/FileOutputStream.hxx"
|
#include "io/FileOutputStream.hxx"
|
||||||
#include "io/BufferedOutputStream.hxx"
|
#include "io/BufferedOutputStream.hxx"
|
||||||
#include "storage/StorageState.hxx"
|
#include "storage/StorageState.hxx"
|
||||||
|
@ -97,7 +97,7 @@ try {
|
||||||
|
|
||||||
FmtDebug(state_file_domain, "Loading state file {}", path_utf8);
|
FmtDebug(state_file_domain, "Loading state file {}", path_utf8);
|
||||||
|
|
||||||
TextFile file(config.path);
|
FileLineReader file{config.path};
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
const SongLoader song_loader(partition.instance.GetDatabase(),
|
const SongLoader song_loader(partition.instance.GetDatabase(),
|
||||||
|
|
|
@ -38,6 +38,7 @@ db_plugins = static_library(
|
||||||
pcre_dep,
|
pcre_dep,
|
||||||
libmpdclient_dep,
|
libmpdclient_dep,
|
||||||
log_dep,
|
log_dep,
|
||||||
|
zlib_dep,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "db/DatabaseLock.hxx"
|
#include "db/DatabaseLock.hxx"
|
||||||
#include "db/DatabaseError.hxx"
|
#include "db/DatabaseError.hxx"
|
||||||
#include "lib/fmt/PathFormatter.hxx"
|
#include "lib/fmt/PathFormatter.hxx"
|
||||||
#include "fs/io/TextFile.hxx"
|
#include "lib/zlib/AutoGunzipFileLineReader.hxx"
|
||||||
#include "io/BufferedOutputStream.hxx"
|
#include "io/BufferedOutputStream.hxx"
|
||||||
#include "io/FileOutputStream.hxx"
|
#include "io/FileOutputStream.hxx"
|
||||||
#include "fs/FileInfo.hxx"
|
#include "fs/FileInfo.hxx"
|
||||||
|
@ -132,7 +132,7 @@ SimpleDatabase::Load()
|
||||||
assert(!path.IsNull());
|
assert(!path.IsNull());
|
||||||
assert(root != nullptr);
|
assert(root != nullptr);
|
||||||
|
|
||||||
TextFile file(path);
|
AutoGunzipFileLineReader file{path};
|
||||||
|
|
||||||
LogDebug(simple_db_domain, "reading DB");
|
LogDebug(simple_db_domain, "reading DB");
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#include "util/StringSplit.hxx"
|
#include "util/StringSplit.hxx"
|
||||||
#include "util/StringStrip.hxx"
|
#include "util/StringStrip.hxx"
|
||||||
#include "util/StringCompare.hxx"
|
#include "util/StringCompare.hxx"
|
||||||
#include "fs/io/TextFile.hxx"
|
#include "io/FileLineReader.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#endif
|
#endif
|
||||||
|
@ -230,7 +231,7 @@ try {
|
||||||
if (config_dir.IsNull())
|
if (config_dir.IsNull())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
TextFile input(config_dir / Path::FromFS("user-dirs.dirs"));
|
FileLineReader input{config_dir / Path::FromFS("user-dirs.dirs")};
|
||||||
char *line;
|
char *line;
|
||||||
while ((line = input.ReadLine()) != nullptr)
|
while ((line = input.ReadLine()) != nullptr)
|
||||||
if (ParseConfigLine(line, name, result))
|
if (ParseConfigLine(line, name, result))
|
||||||
|
|
|
@ -5,7 +5,7 @@ fs_glue = static_library(
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
fs_dep,
|
fs_dep,
|
||||||
fs_io_dep,
|
io_dep,
|
||||||
fmt_dep,
|
fmt_dep,
|
||||||
log_dep,
|
log_dep,
|
||||||
util_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
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#include "TextFile.hxx"
|
#include "AutoGunzipFileLineReader.hxx"
|
||||||
#include "io/FileReader.hxx"
|
#include "io/FileReader.hxx"
|
||||||
#include "io/BufferedReader.hxx"
|
#include "io/BufferedReader.hxx"
|
||||||
#include "lib/zlib/AutoGunzipReader.hxx"
|
#include "lib/zlib/AutoGunzipReader.hxx"
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
TextFile::TextFile(Path path_fs)
|
AutoGunzipFileLineReader::AutoGunzipFileLineReader(Path path_fs)
|
||||||
:file_reader(std::make_unique<FileReader>(path_fs)),
|
:file_reader(std::make_unique<FileReader>(path_fs)),
|
||||||
#ifdef ENABLE_ZLIB
|
#ifdef ENABLE_ZLIB
|
||||||
gunzip_reader(std::make_unique<AutoGunzipReader>(*file_reader)),
|
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 *
|
char *
|
||||||
TextFile::ReadLine()
|
AutoGunzipFileLineReader::ReadLine()
|
||||||
{
|
{
|
||||||
assert(buffered_reader != nullptr);
|
assert(buffered_reader != nullptr);
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_TEXT_FILE_HXX
|
#pragma once
|
||||||
#define MPD_TEXT_FILE_HXX
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_ZLIB
|
||||||
|
|
||||||
#include "io/LineReader.hxx"
|
#include "io/LineReader.hxx"
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
@ -14,24 +16,28 @@ class FileReader;
|
||||||
class AutoGunzipReader;
|
class AutoGunzipReader;
|
||||||
class BufferedReader;
|
class BufferedReader;
|
||||||
|
|
||||||
class TextFile final : public LineReader {
|
class AutoGunzipFileLineReader final : public LineReader {
|
||||||
const std::unique_ptr<FileReader> file_reader;
|
const std::unique_ptr<FileReader> file_reader;
|
||||||
|
|
||||||
#ifdef ENABLE_ZLIB
|
|
||||||
const std::unique_ptr<AutoGunzipReader> gunzip_reader;
|
const std::unique_ptr<AutoGunzipReader> gunzip_reader;
|
||||||
#endif
|
|
||||||
|
|
||||||
const std::unique_ptr<BufferedReader> buffered_reader;
|
const std::unique_ptr<BufferedReader> buffered_reader;
|
||||||
|
|
||||||
public:
|
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 */
|
/* virtual methods from class LineReader */
|
||||||
char *ReadLine() override;
|
char *ReadLine() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "io/FileLineReader.hxx"
|
||||||
|
|
||||||
|
using AutoGunzipFileLineReader = FileLineReader;
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -10,6 +10,7 @@ zlib = static_library(
|
||||||
'GunzipReader.cxx',
|
'GunzipReader.cxx',
|
||||||
'GzipOutputStream.cxx',
|
'GzipOutputStream.cxx',
|
||||||
'AutoGunzipReader.cxx',
|
'AutoGunzipReader.cxx',
|
||||||
|
'AutoGunzipFileLineReader.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
zlib_dep,
|
zlib_dep,
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "db/plugins/simple/DatabaseSave.hxx"
|
#include "db/plugins/simple/DatabaseSave.hxx"
|
||||||
#include "db/plugins/simple/Directory.hxx"
|
#include "db/plugins/simple/Directory.hxx"
|
||||||
|
#include "lib/zlib/AutoGunzipFileLineReader.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "fs/NarrowPath.hxx"
|
#include "fs/NarrowPath.hxx"
|
||||||
#include "fs/io/TextFile.hxx"
|
|
||||||
#include "util/PrintException.hxx"
|
#include "util/PrintException.hxx"
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -20,7 +20,7 @@ try {
|
||||||
const FromNarrowPath db_path = argv[1];
|
const FromNarrowPath db_path = argv[1];
|
||||||
|
|
||||||
Directory root{{}, nullptr};
|
Directory root{{}, nullptr};
|
||||||
TextFile line_reader{db_path};
|
AutoGunzipFileLineReader line_reader{db_path};
|
||||||
db_load_internal(line_reader, root, true);
|
db_load_internal(line_reader, root, true);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -252,6 +252,7 @@ if enable_database
|
||||||
pcm_basic_dep,
|
pcm_basic_dep,
|
||||||
song_dep,
|
song_dep,
|
||||||
db_plugins_dep,
|
db_plugins_dep,
|
||||||
|
zlib_dep,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue