aboutsummaryrefslogtreecommitdiffstats
path: root/src/fs/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/io')
-rw-r--r--src/fs/io/AutoGunzipReader.cxx2
-rw-r--r--src/fs/io/AutoGunzipReader.hxx2
-rw-r--r--src/fs/io/BufferedOutputStream.cxx7
-rw-r--r--src/fs/io/BufferedOutputStream.hxx20
-rw-r--r--src/fs/io/BufferedReader.cxx7
-rw-r--r--src/fs/io/BufferedReader.hxx11
-rw-r--r--src/fs/io/FileOutputStream.cxx187
-rw-r--r--src/fs/io/FileOutputStream.hxx115
-rw-r--r--src/fs/io/FileReader.cxx78
-rw-r--r--src/fs/io/FileReader.hxx35
-rw-r--r--src/fs/io/GunzipReader.cxx2
-rw-r--r--src/fs/io/GunzipReader.hxx2
-rw-r--r--src/fs/io/GzipOutputStream.cxx2
-rw-r--r--src/fs/io/GzipOutputStream.hxx2
-rw-r--r--src/fs/io/OutputStream.hxx2
-rw-r--r--src/fs/io/PeekReader.cxx2
-rw-r--r--src/fs/io/PeekReader.hxx2
-rw-r--r--src/fs/io/Reader.hxx2
-rw-r--r--src/fs/io/StdioOutputStream.hxx2
-rw-r--r--src/fs/io/TextFile.cxx8
-rw-r--r--src/fs/io/TextFile.hxx5
21 files changed, 406 insertions, 89 deletions
diff --git a/src/fs/io/AutoGunzipReader.cxx b/src/fs/io/AutoGunzipReader.cxx
index 2552f7b99..b6d30dfd7 100644
--- a/src/fs/io/AutoGunzipReader.cxx
+++ b/src/fs/io/AutoGunzipReader.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/AutoGunzipReader.hxx b/src/fs/io/AutoGunzipReader.hxx
index 9f031e0f5..29a794aed 100644
--- a/src/fs/io/AutoGunzipReader.hxx
+++ b/src/fs/io/AutoGunzipReader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/BufferedOutputStream.cxx b/src/fs/io/BufferedOutputStream.cxx
index 088a3e279..2268eb50c 100644
--- a/src/fs/io/BufferedOutputStream.cxx
+++ b/src/fs/io/BufferedOutputStream.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -41,17 +41,22 @@ bool
BufferedOutputStream::Write(const void *data, size_t size)
{
if (gcc_unlikely(last_error.IsDefined()))
+ /* the stream has already failed */
return false;
+ /* try to append to the current buffer */
if (AppendToBuffer(data, size))
return true;
+ /* not enough room in the buffer - flush it */
if (!Flush())
return false;
+ /* see if there's now enough room */
if (AppendToBuffer(data, size))
return true;
+ /* too large for the buffer: direct write */
return os.Write(data, size, last_error);
}
diff --git a/src/fs/io/BufferedOutputStream.hxx b/src/fs/io/BufferedOutputStream.hxx
index f2de758a2..63a3f4aee 100644
--- a/src/fs/io/BufferedOutputStream.hxx
+++ b/src/fs/io/BufferedOutputStream.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,14 @@
class OutputStream;
class Error;
+/**
+ * An #OutputStream wrapper that buffers its output to reduce the
+ * number of OutputStream::Write() calls.
+ *
+ * It simplifies error handling by managing an #Error attribute.
+ * Invoke any number of writes, and check for errors in the end using
+ * Check().
+ */
class BufferedOutputStream {
OutputStream &os;
@@ -47,11 +55,18 @@ public:
gcc_printf(2,3)
bool Format(const char *fmt, ...);
+ /**
+ * Returns false if an error has occurred.
+ */
gcc_pure
bool Check() const {
return !last_error.IsDefined();
}
+ /**
+ * Returns false if an error has occurred. In that case, a
+ * copy of the #Error is returned.
+ */
bool Check(Error &error) const {
if (last_error.IsDefined()) {
error.Set(last_error);
@@ -60,6 +75,9 @@ public:
return true;
}
+ /**
+ * Write buffer contents to the #OutputStream.
+ */
bool Flush();
bool Flush(Error &error);
diff --git a/src/fs/io/BufferedReader.cxx b/src/fs/io/BufferedReader.cxx
index ba2f17dcf..9a296d815 100644
--- a/src/fs/io/BufferedReader.cxx
+++ b/src/fs/io/BufferedReader.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -59,8 +59,10 @@ BufferedReader::ReadLine()
{
do {
char *line = ReadBufferedLine(buffer);
- if (line != nullptr)
+ if (line != nullptr) {
+ ++line_number;
return line;
+ }
} while (Fill(true));
if (last_error.IsDefined() || !eof || buffer.IsEmpty())
@@ -78,5 +80,6 @@ BufferedReader::ReadLine()
char *line = buffer.Read().data;
buffer.Clear();
+ ++line_number;
return line;
}
diff --git a/src/fs/io/BufferedReader.hxx b/src/fs/io/BufferedReader.hxx
index 61cc8df83..a0c42d23c 100644
--- a/src/fs/io/BufferedReader.hxx
+++ b/src/fs/io/BufferedReader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -41,9 +41,12 @@ class BufferedReader {
bool eof;
+ unsigned line_number;
+
public:
BufferedReader(Reader &_reader)
- :reader(_reader), buffer(4096), eof(false) {}
+ :reader(_reader), buffer(4096), eof(false),
+ line_number(0) {}
gcc_pure
bool Check() const {
@@ -70,6 +73,10 @@ public:
}
char *ReadLine();
+
+ unsigned GetLineNumber() const {
+ return line_number;
+ }
};
#endif
diff --git a/src/fs/io/FileOutputStream.cxx b/src/fs/io/FileOutputStream.cxx
index 0eff8b5f0..a4ef8f6b4 100644
--- a/src/fs/io/FileOutputStream.cxx
+++ b/src/fs/io/FileOutputStream.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,36 +20,61 @@
#include "config.h"
#include "FileOutputStream.hxx"
#include "fs/FileSystem.hxx"
-#include "system/fd_util.h"
#include "util/Error.hxx"
+FileOutputStream *
+FileOutputStream::Create(Path path, Error &error)
+{
+ FileOutputStream *f = new FileOutputStream(path, error);
+ if (!f->IsDefined()) {
+ delete f;
+ f = nullptr;
+ }
+
+ return f;
+}
+
#ifdef WIN32
FileOutputStream::FileOutputStream(Path _path, Error &error)
- :path(_path),
- handle(CreateFile(path.c_str(), GENERIC_WRITE, 0, nullptr,
- TRUNCATE_EXISTING,
- FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH,
- nullptr))
+ :BaseFileOutputStream(_path)
{
- if (handle == INVALID_HANDLE_VALUE)
- error.FormatLastError("Failed to create %s", path.c_str());
+ SetHandle(CreateFile(_path.c_str(), GENERIC_WRITE, 0, nullptr,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH,
+ nullptr));
+ if (!IsDefined())
+ error.FormatLastError("Failed to create %s",
+ GetPath().ToUTF8().c_str());
+}
+
+uint64_t
+BaseFileOutputStream::Tell() const
+{
+ LONG high = 0;
+ DWORD low = SetFilePointer(handle, 0, &high, FILE_CURRENT);
+ if (low == 0xffffffff)
+ return 0;
+
+ return uint64_t(high) << 32 | uint64_t(low);
}
bool
-FileOutputStream::Write(const void *data, size_t size, Error &error)
+BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
{
assert(IsDefined());
DWORD nbytes;
if (!WriteFile(handle, data, size, &nbytes, nullptr)) {
- error.FormatLastError("Failed to write to %s", path.c_str());
+ error.FormatLastError("Failed to write to %s",
+ path.ToUTF8().c_str());
return false;
}
if (size_t(nbytes) != size) {
error.FormatLastError(ERROR_DISK_FULL,
- "Failed to write to %s", path.c_str());
+ "Failed to write to %s",
+ path.ToUTF8().c_str());
return false;
}
@@ -61,8 +86,7 @@ FileOutputStream::Commit(gcc_unused Error &error)
{
assert(IsDefined());
- CloseHandle(handle);
- handle = INVALID_HANDLE_VALUE;
+ Close();
return true;
}
@@ -71,9 +95,8 @@ FileOutputStream::Cancel()
{
assert(IsDefined());
- CloseHandle(handle);
- handle = INVALID_HANDLE_VALUE;
- RemoveFile(path);
+ Close();
+ RemoveFile(GetPath());
}
#else
@@ -82,28 +105,66 @@ FileOutputStream::Cancel()
#include <unistd.h>
#include <errno.h>
+#ifdef HAVE_LINKAT
+#ifndef O_TMPFILE
+/* supported since Linux 3.11 */
+#define __O_TMPFILE 020000000
+#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
+#include <stdio.h>
+#endif
+
+/**
+ * Open a file using Linux's O_TMPFILE for writing the given file.
+ */
+static bool
+OpenTempFile(FileDescriptor &fd, Path path)
+{
+ const auto directory = path.GetDirectoryName();
+ if (directory.IsNull())
+ return false;
+
+ return fd.Open(directory.c_str(), O_TMPFILE|O_WRONLY, 0666);
+}
+
+#endif /* HAVE_LINKAT */
+
FileOutputStream::FileOutputStream(Path _path, Error &error)
- :path(_path),
- fd(open_cloexec(path.c_str(),
- O_WRONLY|O_CREAT|O_TRUNC,
- 0666))
+ :BaseFileOutputStream(_path)
+{
+#ifdef HAVE_LINKAT
+ /* try Linux's O_TMPFILE first */
+ is_tmpfile = OpenTempFile(SetFD(), GetPath());
+ if (!is_tmpfile) {
+#endif
+ /* fall back to plain POSIX */
+ if (!SetFD().Open(GetPath().c_str(),
+ O_WRONLY|O_CREAT|O_TRUNC,
+ 0666))
+ error.FormatErrno("Failed to create %s",
+ GetPath().c_str());
+#ifdef HAVE_LINKAT
+ }
+#endif
+}
+
+uint64_t
+BaseFileOutputStream::Tell() const
{
- if (fd < 0)
- error.FormatErrno("Failed to create %s", path.c_str());
+ return fd.Tell();
}
bool
-FileOutputStream::Write(const void *data, size_t size, Error &error)
+BaseFileOutputStream::Write(const void *data, size_t size, Error &error)
{
assert(IsDefined());
- ssize_t nbytes = write(fd, data, size);
+ ssize_t nbytes = fd.Write(data, size);
if (nbytes < 0) {
- error.FormatErrno("Failed to write to %s", path.c_str());
+ error.FormatErrno("Failed to write to %s", GetPath().c_str());
return false;
} else if ((size_t)nbytes < size) {
error.FormatErrno(ENOSPC,
- "Failed to write to %s", path.c_str());
+ "Failed to write to %s", GetPath().c_str());
return false;
}
@@ -115,10 +176,27 @@ FileOutputStream::Commit(Error &error)
{
assert(IsDefined());
- bool success = close(fd) == 0;
- fd = -1;
+#if HAVE_LINKAT
+ if (is_tmpfile) {
+ RemoveFile(GetPath());
+
+ /* hard-link the temporary file to the final path */
+ char fd_path[64];
+ snprintf(fd_path, sizeof(fd_path), "/proc/self/fd/%d",
+ GetFD().Get());
+ if (linkat(AT_FDCWD, fd_path, AT_FDCWD, GetPath().c_str(),
+ AT_SYMLINK_FOLLOW) < 0) {
+ error.FormatErrno("Failed to commit %s",
+ GetPath().c_str());
+ Close();
+ return false;
+ }
+ }
+#endif
+
+ bool success = Close();
if (!success)
- error.FormatErrno("Failed to commit %s", path.c_str());
+ error.FormatErrno("Failed to commit %s", GetPath().c_str());
return success;
}
@@ -128,10 +206,53 @@ FileOutputStream::Cancel()
{
assert(IsDefined());
- close(fd);
- fd = -1;
+ Close();
+
+#ifdef HAVE_LINKAT
+ if (!is_tmpfile)
+#endif
+ RemoveFile(GetPath());
+}
+
+#endif
+
+AppendFileOutputStream::AppendFileOutputStream(Path _path, Error &error)
+ :BaseFileOutputStream(_path)
+{
+#ifdef WIN32
+ SetHandle(CreateFile(GetPath().c_str(), GENERIC_WRITE, 0, nullptr,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH,
+ nullptr));
+ if (!IsDefined())
+ error.FormatLastError("Failed to append to %s",
+ GetPath().ToUTF8().c_str());
- RemoveFile(path);
+ if (!SeekEOF()) {
+ error.FormatLastError("Failed seek end-of-file of %s",
+ GetPath().ToUTF8().c_str());
+ Close();
+ }
+#else
+ if (!SetFD().Open(GetPath().c_str(),
+ O_WRONLY|O_APPEND))
+ error.FormatErrno("Failed to append to %s",
+ GetPath().c_str());
+#endif
}
+bool
+AppendFileOutputStream::Commit(gcc_unused Error &error)
+{
+ assert(IsDefined());
+
+#ifdef WIN32
+ return Close();
+#else
+ bool success = Close();
+ if (!success)
+ error.FormatErrno("Failed to commit %s", GetPath().c_str());
+
+ return success;
#endif
+}
diff --git a/src/fs/io/FileOutputStream.hxx b/src/fs/io/FileOutputStream.hxx
index 5b6309957..b182fd03f 100644
--- a/src/fs/io/FileOutputStream.hxx
+++ b/src/fs/io/FileOutputStream.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -25,6 +25,10 @@
#include "fs/AllocatedPath.hxx"
#include "Compiler.h"
+#ifndef WIN32
+#include "system/FileDescriptor.hxx"
+#endif
+
#include <assert.h>
#ifdef WIN32
@@ -33,37 +37,124 @@
class Path;
-class FileOutputStream final : public OutputStream {
- AllocatedPath path;
+class BaseFileOutputStream : public OutputStream {
+ const AllocatedPath path;
#ifdef WIN32
HANDLE handle;
#else
- int fd;
+ FileDescriptor fd;
#endif
-public:
- FileOutputStream(Path _path, Error &error);
+protected:
+#ifdef WIN32
+ template<typename P>
+ BaseFileOutputStream(P &&_path)
+ :path(std::forward<P>(_path)),
+ handle(INVALID_HANDLE_VALUE) {}
+#else
+ template<typename P>
+ BaseFileOutputStream(P &&_path)
+ :path(std::forward<P>(_path)),
+ fd(FileDescriptor::Undefined()) {}
+#endif
- ~FileOutputStream() {
- if (IsDefined())
- Cancel();
+ ~BaseFileOutputStream() {
+ assert(!IsDefined());
}
+#ifdef WIN32
+ void SetHandle(HANDLE _handle) {
+ assert(!IsDefined());
+
+ handle = _handle;
+
+ assert(IsDefined());
+ }
+#else
+ FileDescriptor &SetFD() {
+ assert(!IsDefined());
+
+ return fd;
+ }
+
+ const FileDescriptor &GetFD() const {
+ return fd;
+ }
+#endif
+
+ bool Close() {
+ assert(IsDefined());
+
+#ifdef WIN32
+ CloseHandle(handle);
+ handle = INVALID_HANDLE_VALUE;
+ return true;
+#else
+ return fd.Close();
+#endif
+ }
+
+#ifdef WIN32
+ bool SeekEOF() {
+ return SetFilePointer(handle, 0, nullptr,
+ FILE_END) != 0xffffffff;
+ }
+#endif
+public:
bool IsDefined() const {
#ifdef WIN32
return handle != INVALID_HANDLE_VALUE;
#else
- return fd >= 0;
+ return fd.IsDefined();
#endif
}
- bool Commit(Error &error);
- void Cancel();
+ Path GetPath() const {
+ return path;
+ }
+
+ gcc_pure
+ uint64_t Tell() const;
/* virtual methods from class OutputStream */
bool Write(const void *data, size_t size, Error &error) override;
};
+class FileOutputStream final : public BaseFileOutputStream {
+#ifdef HAVE_LINKAT
+ /**
+ * Was O_TMPFILE used? If yes, then linkat() must be used to
+ * create a link to this file.
+ */
+ bool is_tmpfile;
+#endif
+
+public:
+ FileOutputStream(Path _path, Error &error);
+
+ ~FileOutputStream() {
+ if (IsDefined())
+ Cancel();
+ }
+
+ static FileOutputStream *Create(Path path, Error &error);
+
+ bool Commit(Error &error);
+ void Cancel();
+};
+
+class AppendFileOutputStream final : public BaseFileOutputStream {
+public:
+ AppendFileOutputStream(Path _path, Error &error);
+
+ ~AppendFileOutputStream() {
+ if (IsDefined())
+ Close();
+ }
+
+ bool Commit(Error &error);
+};
+
#endif
diff --git a/src/fs/io/FileReader.cxx b/src/fs/io/FileReader.cxx
index d63cd8ab0..e54f6f3a8 100644
--- a/src/fs/io/FileReader.cxx
+++ b/src/fs/io/FileReader.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -19,7 +19,7 @@
#include "config.h"
#include "FileReader.hxx"
-#include "system/fd_util.h"
+#include "fs/FileInfo.hxx"
#include "util/Error.hxx"
#ifdef WIN32
@@ -30,8 +30,18 @@ FileReader::FileReader(Path _path, Error &error)
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr))
{
- if (handle == INVALID_HANDLE_VALUE)
- error.FormatLastError("Failed to open %s", path.c_str());
+ if (handle == INVALID_HANDLE_VALUE) {
+ const auto path_utf8 = path.ToUTF8();
+ error.FormatLastError("Failed to open %s", path_utf8.c_str());
+ }
+}
+
+bool
+FileReader::GetFileInfo(FileInfo &info, Error &error) const
+{
+ assert(IsDefined());
+
+ return ::GetFileInfo(path, info, error);
}
size_t
@@ -41,13 +51,28 @@ FileReader::Read(void *data, size_t size, Error &error)
DWORD nbytes;
if (!ReadFile(handle, data, size, &nbytes, nullptr)) {
- error.FormatLastError("Failed to read from %s", path.c_str());
+ const auto path_utf8 = path.ToUTF8();
+ error.FormatLastError("Failed to read from %s",
+ path_utf8.c_str());
nbytes = 0;
}
return nbytes;
}
+bool
+FileReader::Seek(off_t offset, Error &error)
+{
+ assert(IsDefined());
+
+ auto result = SetFilePointer(handle, offset, nullptr, FILE_BEGIN);
+ const bool success = result != INVALID_SET_FILE_POINTER;
+ if (!success)
+ error.SetLastError("Failed to seek");
+
+ return success;
+}
+
void
FileReader::Close()
{
@@ -58,26 +83,33 @@ FileReader::Close()
#else
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-
FileReader::FileReader(Path _path, Error &error)
- :path(_path),
- fd(open_cloexec(path.c_str(),
- O_RDONLY,
- 0))
+ :path(_path)
{
- if (fd < 0)
+ fd.OpenReadOnly(path.c_str());
+ if (!fd.IsDefined())
error.FormatErrno("Failed to open %s", path.c_str());
}
+bool
+FileReader::GetFileInfo(FileInfo &info, Error &error) const
+{
+ assert(IsDefined());
+
+ const bool success = fstat(fd.Get(), &info.st) == 0;
+ if (!success)
+ error.FormatErrno("Failed to access %s",
+ path.ToUTF8().c_str());
+
+ return success;
+}
+
size_t
FileReader::Read(void *data, size_t size, Error &error)
{
assert(IsDefined());
- ssize_t nbytes = read(fd, data, size);
+ ssize_t nbytes = fd.Read(data, size);
if (nbytes < 0) {
error.FormatErrno("Failed to read from %s", path.c_str());
nbytes = 0;
@@ -86,13 +118,25 @@ FileReader::Read(void *data, size_t size, Error &error)
return nbytes;
}
+bool
+FileReader::Seek(off_t offset, Error &error)
+{
+ assert(IsDefined());
+
+ auto result = fd.Seek(offset);
+ const bool success = result >= 0;
+ if (!success)
+ error.SetErrno("Failed to seek");
+
+ return success;
+}
+
void
FileReader::Close()
{
assert(IsDefined());
- close(fd);
- fd = -1;
+ fd.Close();
}
#endif
diff --git a/src/fs/io/FileReader.hxx b/src/fs/io/FileReader.hxx
index 9f459aee2..642fc5ed1 100644
--- a/src/fs/io/FileReader.hxx
+++ b/src/fs/io/FileReader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -25,6 +25,10 @@
#include "fs/AllocatedPath.hxx"
#include "Compiler.h"
+#ifndef WIN32
+#include "system/FileDescriptor.hxx"
+#endif
+
#include <assert.h>
#ifdef WIN32
@@ -32,6 +36,7 @@
#endif
class Path;
+class FileInfo;
class FileReader final : public Reader {
AllocatedPath path;
@@ -39,12 +44,26 @@ class FileReader final : public Reader {
#ifdef WIN32
HANDLE handle;
#else
- int fd;
+ FileDescriptor fd;
#endif
public:
FileReader(Path _path, Error &error);
+#ifdef WIN32
+ FileReader(FileReader &&other)
+ :path(std::move(other.path)),
+ handle(other.handle) {
+ other.handle = INVALID_HANDLE_VALUE;
+ }
+#else
+ FileReader(FileReader &&other)
+ :path(std::move(other.path)),
+ fd(other.fd) {
+ other.fd.SetUndefined();
+ }
+#endif
+
~FileReader() {
if (IsDefined())
Close();
@@ -55,12 +74,22 @@ public:
#ifdef WIN32
return handle != INVALID_HANDLE_VALUE;
#else
- return fd >= 0;
+ return fd.IsDefined();
#endif
}
+#ifndef WIN32
+ FileDescriptor GetFD() const {
+ return fd;
+ }
+#endif
+
void Close();
+ bool GetFileInfo(FileInfo &info, Error &error) const;
+
+ bool Seek(off_t offset, Error &error);
+
/* virtual methods from class Reader */
size_t Read(void *data, size_t size, Error &error) override;
};
diff --git a/src/fs/io/GunzipReader.cxx b/src/fs/io/GunzipReader.cxx
index ad5e41784..78f5b2c69 100644
--- a/src/fs/io/GunzipReader.cxx
+++ b/src/fs/io/GunzipReader.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/GunzipReader.hxx b/src/fs/io/GunzipReader.hxx
index 06c44bad6..381d1af5e 100644
--- a/src/fs/io/GunzipReader.hxx
+++ b/src/fs/io/GunzipReader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/GzipOutputStream.cxx b/src/fs/io/GzipOutputStream.cxx
index 27ae6b2ad..d2a693b87 100644
--- a/src/fs/io/GzipOutputStream.cxx
+++ b/src/fs/io/GzipOutputStream.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/GzipOutputStream.hxx b/src/fs/io/GzipOutputStream.hxx
index 27ee2dd24..fdab7bca4 100644
--- a/src/fs/io/GzipOutputStream.hxx
+++ b/src/fs/io/GzipOutputStream.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/OutputStream.hxx b/src/fs/io/OutputStream.hxx
index 71311c71f..f7d101180 100644
--- a/src/fs/io/OutputStream.hxx
+++ b/src/fs/io/OutputStream.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/PeekReader.cxx b/src/fs/io/PeekReader.cxx
index 2e8042ab6..ec9520a37 100644
--- a/src/fs/io/PeekReader.cxx
+++ b/src/fs/io/PeekReader.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/PeekReader.hxx b/src/fs/io/PeekReader.hxx
index 32180b0a8..c00ed66be 100644
--- a/src/fs/io/PeekReader.hxx
+++ b/src/fs/io/PeekReader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/Reader.hxx b/src/fs/io/Reader.hxx
index d41e92dd0..657f96ac2 100644
--- a/src/fs/io/Reader.hxx
+++ b/src/fs/io/Reader.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/StdioOutputStream.hxx b/src/fs/io/StdioOutputStream.hxx
index c1c0a00bd..88dbe6f00 100644
--- a/src/fs/io/StdioOutputStream.hxx
+++ b/src/fs/io/StdioOutputStream.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/fs/io/TextFile.cxx b/src/fs/io/TextFile.cxx
index 28d6dabcb..9866da08a 100644
--- a/src/fs/io/TextFile.cxx
+++ b/src/fs/io/TextFile.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -28,14 +28,14 @@
TextFile::TextFile(Path path_fs, Error &error)
:file_reader(new FileReader(path_fs, error)),
-#ifdef HAVE_ZLIB
+#ifdef ENABLE_ZLIB
gunzip_reader(file_reader->IsDefined()
? new AutoGunzipReader(*file_reader)
: nullptr),
#endif
buffered_reader(file_reader->IsDefined()
? new BufferedReader(*
-#ifdef HAVE_ZLIB
+#ifdef ENABLE_ZLIB
gunzip_reader
#else
file_reader
@@ -48,7 +48,7 @@ TextFile::TextFile(Path path_fs, Error &error)
TextFile::~TextFile()
{
delete buffered_reader;
-#ifdef HAVE_ZLIB
+#ifdef ENABLE_ZLIB
delete gunzip_reader;
#endif
delete file_reader;
diff --git a/src/fs/io/TextFile.hxx b/src/fs/io/TextFile.hxx
index 5577363e7..bee9e8c23 100644
--- a/src/fs/io/TextFile.hxx
+++ b/src/fs/io/TextFile.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -34,7 +34,7 @@ class BufferedReader;
class TextFile {
FileReader *const file_reader;
-#ifdef HAVE_ZLIB
+#ifdef ENABLE_ZLIB
AutoGunzipReader *const gunzip_reader;
#endif
@@ -59,7 +59,6 @@ public:
* Use Check() after nullptr has been returned to check
* whether an error occurred or end-of-file has been reached.
*
- * @param file the source file, opened in text mode
* @return a pointer to the line, or nullptr on end-of-file or error
*/
char *ReadLine();