Skip to content

Commit

Permalink
Merge branch 'v0.20.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jul 6, 2018
2 parents 45139f9 + 6f3c0d0 commit 9a29d02
Show file tree
Hide file tree
Showing 19 changed files with 316 additions and 62 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ libmpd_a_SOURCES += \
endif

CURL_SOURCES = \
src/lib/curl/Error.hxx \
src/lib/curl/Delegate.cxx src/lib/curl/Delegate.hxx \
src/lib/curl/Parser.hxx \
src/lib/curl/Version.cxx src/lib/curl/Version.hxx \
Expand Down Expand Up @@ -771,6 +772,7 @@ NFS_SOURCES = \
src/lib/nfs/Cancellable.hxx \
src/lib/nfs/Lease.hxx \
src/lib/nfs/Connection.cxx src/lib/nfs/Connection.hxx \
src/lib/nfs/Error.cxx src/lib/nfs/Error.hxx \
src/lib/nfs/Manager.cxx src/lib/nfs/Manager.hxx \
src/lib/nfs/Glue.cxx src/lib/nfs/Glue.hxx \
src/lib/nfs/Base.cxx src/lib/nfs/Base.hxx \
Expand Down Expand Up @@ -1375,6 +1377,7 @@ endif
#

libinput_a_SOURCES = \
src/input/Error.cxx src/input/Error.hxx \
src/input/Init.cxx src/input/Init.hxx \
src/input/Registry.cxx src/input/Registry.hxx \
src/input/Open.cxx \
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ ver 0.20.21 (not yet released)
* database
- proxy: add "password" setting
- proxy: support tags "ArtistSort", "AlbumArtistSort", "AlbumSort"
- simple: allow .mpdignore comments only at start of line
* output
- httpd: remove broken DLNA support code

ver 0.20.20 (2018/05/22)
* protocol
Expand Down
4 changes: 2 additions & 2 deletions python/build/libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
)

ffmpeg = FfmpegProject(
'http://ffmpeg.org/releases/ffmpeg-4.0.tar.xz',
'ed945daf40b124e77a685893cc025d086f638bc703183460aff49508edb3a43f',
'http://ffmpeg.org/releases/ffmpeg-4.0.1.tar.xz',
'605f5c01c60db35d3b617a79cabb2c7032412be243554602eeed1b628125c0ee',
'lib/libavcodec.a',
[
'--disable-shared', '--enable-static',
Expand Down
1 change: 0 additions & 1 deletion src/AudioFormat.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "pcm/SampleFormat.hxx"
#include "Compiler.h"

#include <assert.h>
#include <stdint.h>
#include <stddef.h>

Expand Down
35 changes: 14 additions & 21 deletions src/db/update/ExcludeList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#include "ExcludeList.hxx"
#include "fs/Path.hxx"
#include "fs/NarrowPath.hxx"
#include "fs/io/TextFile.hxx"
#include "system/Error.hxx"
#include "input/TextInputStream.hxx"
#include "util/StringStrip.hxx"
#include "Log.hxx"

Expand All @@ -36,35 +35,29 @@
#include <assert.h>
#include <string.h>

inline void
ExcludeList::ParseLine(char *line) noexcept
{
char *p = Strip(line);
if (*p != 0 && *p != '#')
patterns.emplace_front(p);
}

bool
ExcludeList::LoadFile(Path path_fs) noexcept
try {
ExcludeList::Load(InputStreamPtr is)
{
#ifdef HAVE_CLASS_GLOB
TextFile file(path_fs);
TextInputStream tis(std::move(is));

char *line;
while ((line = file.ReadLine()) != nullptr) {
char *p = strchr(line, '#');
if (p != nullptr)
*p = 0;

p = Strip(line);
if (*p != 0)
patterns.emplace_front(p);
}
while ((line = tis.ReadLine()) != nullptr)
ParseLine(line);
#else
/* not implemented */
(void)path_fs;
#endif

return true;
} catch (const std::system_error &e) {
if (!IsFileNotFound(e))
LogError(e);
return false;
} catch (...) {
LogError(std::current_exception());
return false;
}

bool
Expand Down
6 changes: 5 additions & 1 deletion src/db/update/ExcludeList.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "check.h"
#include "Compiler.h"
#include "fs/Glob.hxx"
#include "input/Ptr.hxx"

#ifdef HAVE_CLASS_GLOB
#include <forward_list>
Expand Down Expand Up @@ -62,13 +63,16 @@ public:
/**
* Loads and parses a .mpdignore file.
*/
bool LoadFile(Path path_fs) noexcept;
bool Load(InputStreamPtr is);

/**
* Checks whether one of the patterns in the .mpdignore file matches
* the specified file name.
*/
bool Check(Path name_fs) const noexcept;

private:
void ParseLine(char *line) noexcept;
};


Expand Down
16 changes: 11 additions & 5 deletions src/db/update/Walk.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
#include "storage/FileInfo.hxx"
#include "input/InputStream.hxx"
#include "input/Error.hxx"
#include "util/Alloc.hxx"
#include "util/StringCompare.hxx"
#include "util/UriUtil.hxx"
Expand Down Expand Up @@ -346,11 +348,15 @@ UpdateWalk::UpdateDirectory(Directory &directory,

ExcludeList child_exclude_list(exclude_list);

{
const auto exclude_path_fs =
storage.MapChildFS(directory.GetPath(), ".mpdignore");
if (!exclude_path_fs.IsNull())
child_exclude_list.LoadFile(exclude_path_fs);
try {
Mutex mutex;
auto is = InputStream::OpenReady(PathTraitsUTF8::Build(storage.MapUTF8(directory.GetPath()).c_str(),
".mpdignore").c_str(),
mutex);
child_exclude_list.Load(std::move(is));
} catch (...) {
if (!IsFileNotFound(std::current_exception()))
LogError(std::current_exception());
}

if (!child_exclude_list.IsEmpty())
Expand Down
53 changes: 53 additions & 0 deletions src/input/Error.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "config.h"
#include "Error.hxx"
#include "system/Error.hxx"

#ifdef ENABLE_CURL
#include "lib/curl/Error.hxx"
#endif

#ifdef ENABLE_NFS
#include "lib/nfs/Error.hxx"
#include <nfsc/libnfs-raw-nfs.h>
#endif

bool
IsFileNotFound(std::exception_ptr ep)
{
try {
std::rethrow_exception(ep);
} catch (const std::system_error &e) {
return IsFileNotFound(e);
#ifdef ENABLE_CURL
} catch (const HttpStatusError &e) {
return e.GetStatus() == 404;
#endif
#ifdef ENABLE_NFS
} catch (const NfsClientError &e) {
return e.GetCode() == NFS3ERR_NOENT;
#endif
} catch (...) {
}

return false;
}

37 changes: 37 additions & 0 deletions src/input/Error.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef INPUT_ERROR_HXX
#define INPUT_ERROR_HXX

#include "check.h"
#include "Compiler.h"

#include <exception>

/**
* Was this exception thrown because the requested file does not
* exist? This function attempts to recognize exceptions thrown by
* various input plugins.
*/
gcc_pure
bool
IsFileNotFound(std::exception_ptr e);

#endif
5 changes: 4 additions & 1 deletion src/input/plugins/CurlInputPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "config.h"
#include "CurlInputPlugin.hxx"
#include "lib/curl/Error.hxx"
#include "lib/curl/Easy.hxx"
#include "lib/curl/Global.hxx"
#include "lib/curl/Init.hxx"
Expand Down Expand Up @@ -194,7 +195,9 @@ CurlInputStream::OnHeaders(unsigned status,
assert(!icy || !icy->IsDefined());

if (status < 200 || status >= 300)
throw FormatRuntimeError("got HTTP status %ld", status);
throw HttpStatusError(status,
StringFormat<40>("got HTTP status %u",
status).c_str());

const std::lock_guard<Mutex> protect(mutex);

Expand Down
42 changes: 42 additions & 0 deletions src/lib/curl/Error.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef CURL_ERROR_HXX
#define CURL_ERROR_HXX

#include <stdexcept>

/**
* Thrown when an unsuccessful status was received from the HTTP
* server.
*/
class HttpStatusError : public std::runtime_error {
unsigned status;

public:
template<typename M>
explicit HttpStatusError(unsigned _status, M &&_msg) noexcept
:std::runtime_error(std::forward<M>(_msg)), status(_status) {}

unsigned GetStatus() const noexcept {
return status;
}
};

#endif
3 changes: 2 additions & 1 deletion src/lib/nfs/Connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "config.h"
#include "Connection.hxx"
#include "Error.hxx"
#include "Lease.hxx"
#include "Callback.hxx"
#include "event/Loop.hxx"
Expand Down Expand Up @@ -139,7 +140,7 @@ NfsConnection::CancellableCallback::Callback(int err, void *data) noexcept
if (err >= 0)
cb.OnNfsCallback((unsigned)err, data);
else
cb.OnNfsError(std::make_exception_ptr(std::runtime_error((const char *)data)));
cb.OnNfsError(std::make_exception_ptr(NfsClientError(-err, (const char *)data)));
} else {
if (open) {
/* a nfs_open_async() call was cancelled - to
Expand Down

0 comments on commit 9a29d02

Please sign in to comment.