aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-31 22:17:49 +0100
committerMax Kellermann <max@duempel.org>2014-01-31 22:17:49 +0100
commit26970579b86c4dfb8e7a11cbc12edac670e4f0e2 (patch)
tree4f859ab8b534fb3d2fc637624cc4c412797a1efd /src/db
parent04b4f534889719fd822aff5cf9b78a50d1da47ad (diff)
downloadmpd-26970579b86c4dfb8e7a11cbc12edac670e4f0e2.tar.gz
mpd-26970579b86c4dfb8e7a11cbc12edac670e4f0e2.tar.xz
mpd-26970579b86c4dfb8e7a11cbc12edac670e4f0e2.zip
db/update/Editor: add locking method variants
Diffstat (limited to 'src/db')
-rw-r--r--src/db/update/Container.cxx4
-rw-r--r--src/db/update/Editor.cxx16
-rw-r--r--src/db/update/Editor.hxx10
-rw-r--r--src/db/update/UpdateSong.cxx18
-rw-r--r--src/db/update/Walk.cxx15
5 files changed, 36 insertions, 27 deletions
diff --git a/src/db/update/Container.cxx b/src/db/update/Container.cxx
index 38aacea0a..33e29953d 100644
--- a/src/db/update/Container.cxx
+++ b/src/db/update/Container.cxx
@@ -118,9 +118,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
}
if (tnum == 1) {
- db_lock();
- editor.DeleteDirectory(contdir);
- db_unlock();
+ editor.LockDeleteDirectory(contdir);
return false;
} else
return true;
diff --git a/src/db/update/Editor.cxx b/src/db/update/Editor.cxx
index 369bad24b..c8f58931f 100644
--- a/src/db/update/Editor.cxx
+++ b/src/db/update/Editor.cxx
@@ -47,6 +47,14 @@ DatabaseEditor::DeleteSong(Directory &dir, Song *del)
db_lock();
}
+void
+DatabaseEditor::LockDeleteSong(Directory &parent, Song *song)
+{
+ db_lock();
+ DeleteSong(parent, song);
+ db_unlock();
+}
+
/**
* Recursively remove all sub directories and songs from a directory,
* leaving an empty directory.
@@ -77,6 +85,14 @@ DatabaseEditor::DeleteDirectory(Directory *directory)
directory->Delete();
}
+void
+DatabaseEditor::LockDeleteDirectory(Directory *directory)
+{
+ db_lock();
+ DeleteDirectory(directory);
+ db_unlock();
+}
+
bool
DatabaseEditor::DeleteNameIn(Directory &parent, const char *name)
{
diff --git a/src/db/update/Editor.hxx b/src/db/update/Editor.hxx
index a9093d662..b1c99095f 100644
--- a/src/db/update/Editor.hxx
+++ b/src/db/update/Editor.hxx
@@ -40,6 +40,11 @@ public:
void DeleteSong(Directory &parent, Song *song);
/**
+ * DeleteSong() with automatic locking.
+ */
+ void LockDeleteSong(Directory &parent, Song *song);
+
+ /**
* Recursively free a directory and all its contents.
*
* Caller must lock the #db_mutex.
@@ -47,6 +52,11 @@ public:
void DeleteDirectory(Directory *directory);
/**
+ * DeleteDirectory() with automatic locking.
+ */
+ void LockDeleteDirectory(Directory *directory);
+
+ /**
* Caller must NOT lock the #db_mutex.
*
* @return true if the database was modified
diff --git a/src/db/update/UpdateSong.cxx b/src/db/update/UpdateSong.cxx
index afd609f9a..751d8bfe9 100644
--- a/src/db/update/UpdateSong.cxx
+++ b/src/db/update/UpdateSong.cxx
@@ -42,11 +42,8 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
FormatError(update_domain,
"no read permissions on %s/%s",
directory.GetPath(), name);
- if (song != nullptr) {
- db_lock();
- editor.DeleteSong(directory, song);
- db_unlock();
- }
+ if (song != nullptr)
+ editor.LockDeleteSong(directory, song);
return;
}
@@ -54,11 +51,8 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
if (!(song != nullptr && st->st_mtime == song->mtime &&
!walk_discard) &&
UpdateContainerFile(directory, name, suffix, st)) {
- if (song != nullptr) {
- db_lock();
- editor.DeleteSong(directory, song);
- db_unlock();
- }
+ if (song != nullptr)
+ editor.LockDeleteSong(directory, song);
return;
}
@@ -88,9 +82,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
FormatDebug(update_domain,
"deleting unrecognized file %s/%s",
directory.GetPath(), name);
- db_lock();
- editor.DeleteSong(directory, song);
- db_unlock();
+ editor.LockDeleteSong(directory, song);
}
modified = true;
diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index 1ca589456..ff59fe960 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -107,9 +107,7 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory)
if (directory_exists(*child))
continue;
- db_lock();
- editor.DeleteDirectory(child);
- db_unlock();
+ editor.LockDeleteDirectory(child);
modified = true;
}
@@ -118,9 +116,7 @@ UpdateWalk::PurgeDeletedFromDirectory(Directory &directory)
directory_for_each_song_safe(song, ns, directory) {
const auto path = map_song_fs(*song);
if (path.IsNull() || !FileExists(path)) {
- db_lock();
- editor.DeleteSong(directory, song);
- db_unlock();
+ editor.LockDeleteSong(directory, song);
modified = true;
}
@@ -223,11 +219,8 @@ UpdateWalk::UpdateDirectoryChild(Directory &directory,
assert(&directory == subdir->parent);
- if (!UpdateDirectory(*subdir, st)) {
- db_lock();
- editor.DeleteDirectory(subdir);
- db_unlock();
- }
+ if (!UpdateDirectory(*subdir, st))
+ editor.LockDeleteDirectory(subdir);
} else {
FormatDebug(update_domain,
"%s is not a directory, archive or music", name);