aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlaylistFile.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/PlaylistFile.cxx102
1 files changed, 57 insertions, 45 deletions
diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx
index e5285ad04..ab269378a 100644
--- a/src/PlaylistFile.cxx
+++ b/src/PlaylistFile.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,16 +20,15 @@
#include "config.h"
#include "PlaylistFile.hxx"
#include "PlaylistSave.hxx"
-#include "PlaylistInfo.hxx"
-#include "PlaylistVector.hxx"
-#include "DatabasePlugin.hxx"
-#include "DatabaseGlue.hxx"
-#include "Song.hxx"
+#include "db/PlaylistInfo.hxx"
+#include "db/PlaylistVector.hxx"
+#include "DetachedSong.hxx"
+#include "SongLoader.hxx"
#include "Mapper.hxx"
-#include "TextFile.hxx"
-#include "ConfigGlobal.hxx"
-#include "ConfigOption.hxx"
-#include "ConfigDefaults.hxx"
+#include "fs/io/TextFile.hxx"
+#include "config/ConfigGlobal.hxx"
+#include "config/ConfigOption.hxx"
+#include "config/ConfigDefaults.hxx"
#include "Idle.hxx"
#include "fs/Limits.hxx"
#include "fs/AllocatedPath.hxx"
@@ -37,16 +36,12 @@
#include "fs/Charset.hxx"
#include "fs/FileSystem.hxx"
#include "fs/DirectoryReader.hxx"
+#include "util/StringUtil.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
-#include <glib.h>
-
#include <assert.h>
-#include <sys/types.h>
#include <sys/stat.h>
-#include <unistd.h>
-#include <dirent.h>
#include <string.h>
#include <errno.h>
@@ -125,6 +120,29 @@ spl_map_to_fs(const char *name_utf8, Error &error)
return path_fs;
}
+gcc_pure
+static bool
+IsNotFoundError(const Error &error)
+{
+#ifdef WIN32
+ return error.IsDomain(win32_domain) &&
+ error.GetCode() == ERROR_FILE_NOT_FOUND;
+#else
+ return error.IsDomain(errno_domain) &&
+ error.GetCode() == ENOENT;
+#endif
+}
+
+static void
+TranslatePlaylistError(Error &error)
+{
+ if (IsNotFoundError(error)) {
+ error.Clear();
+ error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_LIST),
+ "No such playlist");
+ }
+}
+
/**
* Create an #Error for the current errno.
*/
@@ -145,8 +163,8 @@ playlist_errno(Error &error)
static bool
LoadPlaylistFileInfo(PlaylistInfo &info,
- const AllocatedPath &parent_path_fs,
- const AllocatedPath &name_fs)
+ const Path parent_path_fs,
+ const Path name_fs)
{
const char *name_fs_str = name_fs.c_str();
size_t name_length = strlen(name_fs_str);
@@ -155,7 +173,7 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
memchr(name_fs_str, '\n', name_length) != nullptr)
return false;
- if (!g_str_has_suffix(name_fs_str, PLAYLIST_FILE_SUFFIX))
+ if (!StringEndsWith(name_fs_str, PLAYLIST_FILE_SUFFIX))
return false;
const auto path_fs = AllocatedPath::Build(parent_path_fs, name_fs);
@@ -163,10 +181,9 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
if (!StatFile(path_fs, st) || !S_ISREG(st.st_mode))
return false;
- char *name = g_strndup(name_fs_str,
- name_length + 1 - sizeof(PLAYLIST_FILE_SUFFIX));
- std::string name_utf8 = PathToUTF8(name);
- g_free(name);
+ std::string name(name_fs_str,
+ name_length + 1 - sizeof(PLAYLIST_FILE_SUFFIX));
+ std::string name_utf8 = PathToUTF8(name.c_str());
if (name_utf8.empty())
return false;
@@ -238,9 +255,9 @@ LoadPlaylistFile(const char *utf8path, Error &error)
if (path_fs.IsNull())
return contents;
- TextFile file(path_fs);
+ TextFile file(path_fs, error);
if (file.HasFailed()) {
- playlist_errno(error);
+ TranslatePlaylistError(error);
return contents;
}
@@ -252,9 +269,10 @@ LoadPlaylistFile(const char *utf8path, Error &error)
std::string uri_utf8;
if (!uri_has_scheme(s)) {
+#ifdef ENABLE_DATABASE
uri_utf8 = map_fs_to_utf8(s);
if (uri_utf8.empty()) {
- if (PathTraits::IsAbsoluteFS(s)) {
+ if (PathTraitsFS::IsAbsolute(s)) {
uri_utf8 = PathToUTF8(s);
if (uri_utf8.empty())
continue;
@@ -263,6 +281,9 @@ LoadPlaylistFile(const char *utf8path, Error &error)
} else
continue;
}
+#else
+ continue;
+#endif
} else {
uri_utf8 = PathToUTF8(s);
if (uri_utf8.empty())
@@ -369,7 +390,7 @@ spl_remove_index(const char *utf8path, unsigned pos, Error &error)
}
bool
-spl_append_song(const char *utf8path, const Song &song, Error &error)
+spl_append_song(const char *utf8path, const DetachedSong &song, Error &error)
{
if (spl_map(error).IsNull())
return false;
@@ -407,26 +428,17 @@ spl_append_song(const char *utf8path, const Song &song, Error &error)
}
bool
-spl_append_uri(const char *url, const char *utf8file, Error &error)
+spl_append_uri(const char *utf8file,
+ const SongLoader &loader, const char *url,
+ Error &error)
{
- if (uri_has_scheme(url)) {
- Song *song = Song::NewRemote(url);
- bool success = spl_append_song(utf8file, *song, error);
- song->Free();
- return success;
- } else {
- const Database *db = GetDatabase(error);
- if (db == nullptr)
- return false;
-
- Song *song = db->GetSong(url, error);
- if (song == nullptr)
- return false;
-
- bool success = spl_append_song(utf8file, *song, error);
- db->ReturnSong(song);
- return success;
- }
+ DetachedSong *song = loader.LoadSong(url, error);
+ if (song == nullptr)
+ return false;
+
+ bool success = spl_append_song(utf8file, *song, error);
+ delete song;
+ return success;
}
static bool