aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/SimpleDatabasePlugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/db/SimpleDatabasePlugin.cxx')
-rw-r--r--src/db/SimpleDatabasePlugin.cxx52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index e7ea7a62d..3d947c042 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.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
@@ -22,24 +22,26 @@
#include "DatabaseSelection.hxx"
#include "DatabaseHelpers.hxx"
#include "Directory.hxx"
+#include "Song.hxx"
#include "SongFilter.hxx"
#include "DatabaseSave.hxx"
#include "DatabaseLock.hxx"
#include "DatabaseError.hxx"
-#include "TextFile.hxx"
+#include "fs/TextFile.hxx"
#include "ConfigData.hxx"
#include "fs/FileSystem.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
-#include <sys/types.h>
#include <errno.h>
static constexpr Domain simple_db_domain("simple_db");
Database *
-SimpleDatabase::Create(const config_param &param, Error &error)
+SimpleDatabase::Create(gcc_unused EventLoop &loop,
+ gcc_unused DatabaseListener &listener,
+ const config_param &param, Error &error)
{
SimpleDatabase *db = new SimpleDatabase();
if (!db->Configure(param, error)) {
@@ -72,7 +74,7 @@ SimpleDatabase::Check(Error &error) const
assert(!path.IsNull());
/* Check if the file exists */
- if (!CheckAccess(path, F_OK)) {
+ if (!CheckAccess(path)) {
/* If the file doesn't exist, we can't check if we can write
* it, so we are going to try to get the directory path, and
* see if we can write a file in that */
@@ -95,6 +97,7 @@ SimpleDatabase::Check(Error &error) const
return false;
}
+#ifndef WIN32
/* Check if we can write to the directory */
if (!CheckAccess(dirPath, X_OK | W_OK)) {
const int e = errno;
@@ -103,7 +106,7 @@ SimpleDatabase::Check(Error &error) const
dirPath_utf8.c_str());
return false;
}
-
+#endif
return true;
}
@@ -122,12 +125,14 @@ SimpleDatabase::Check(Error &error) const
return false;
}
+#ifndef WIN32
/* And check that we can write to it */
if (!CheckAccess(path, R_OK | W_OK)) {
error.FormatErrno("Can't open db file \"%s\" for reading/writing",
path_utf8.c_str());
return false;
}
+#endif
return true;
}
@@ -166,7 +171,7 @@ SimpleDatabase::Open(Error &error)
#endif
if (!Load(error)) {
- root->Free();
+ delete root;
LogError(error);
error.Clear();
@@ -186,36 +191,41 @@ SimpleDatabase::Close()
assert(root != nullptr);
assert(borrowed_song_count == 0);
- root->Free();
+ delete root;
}
-Song *
+const LightSong *
SimpleDatabase::GetSong(const char *uri, Error &error) const
{
assert(root != nullptr);
+ assert(borrowed_song_count == 0);
db_lock();
- Song *song = root->LookupSong(uri);
+ const Song *song = root->LookupSong(uri);
db_unlock();
- if (song == nullptr)
+ if (song == nullptr) {
error.Format(db_domain, DB_NOT_FOUND,
"No such song: %s", uri);
+ return nullptr;
+ }
+
+ light_song = song->Export();
+
#ifndef NDEBUG
- else
- ++const_cast<unsigned &>(borrowed_song_count);
+ ++borrowed_song_count;
#endif
- return song;
+ return &light_song;
}
void
-SimpleDatabase::ReturnSong(gcc_unused Song *song) const
+SimpleDatabase::ReturnSong(gcc_unused const LightSong *song) const
{
- assert(song != nullptr);
+ assert(song == &light_song);
#ifndef NDEBUG
assert(borrowed_song_count > 0);
- --const_cast<unsigned &>(borrowed_song_count);
+ --borrowed_song_count;
#endif
}
@@ -243,9 +253,11 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
if (directory == nullptr) {
if (visit_song) {
Song *song = root->LookupSong(selection.uri.c_str());
- if (song != nullptr)
- return !selection.Match(*song) ||
- visit_song(*song, error);
+ if (song != nullptr) {
+ const LightSong song2 = song->Export();
+ return !selection.Match(song2) ||
+ visit_song(song2, error);
+ }
}
error.Set(db_domain, DB_NOT_FOUND, "No such directory");