aboutsummaryrefslogtreecommitdiffstats
path: root/src/SongUpdate.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-15 12:05:44 +0100
committerMax Kellermann <max@duempel.org>2014-01-15 12:05:44 +0100
commit9fb82f9687c10ee8430437a97e263c85f968bddb (patch)
tree16ee0270c77e1a9662ac6ef3ba4e0959d5488f06 /src/SongUpdate.cxx
parentdf80deb0708f9abe911dc3533c0d3b310f73650c (diff)
downloadmpd-9fb82f9687c10ee8430437a97e263c85f968bddb.tar.gz
mpd-9fb82f9687c10ee8430437a97e263c85f968bddb.tar.xz
mpd-9fb82f9687c10ee8430437a97e263c85f968bddb.zip
DetachedSong: add method Update()
Don't create an intermediate Song instance when all we want is a DetachedSong.
Diffstat (limited to 'src/SongUpdate.cxx')
-rw-r--r--src/SongUpdate.cxx37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx
index 70a05bf2a..669d0568d 100644
--- a/src/SongUpdate.cxx
+++ b/src/SongUpdate.cxx
@@ -19,6 +19,7 @@
#include "config.h" /* must be first for large file support */
#include "Song.hxx"
+#include "DetachedSong.hxx"
#include "util/UriUtil.hxx"
#include "Directory.hxx"
#include "Mapper.hxx"
@@ -126,3 +127,39 @@ Song::UpdateFileInArchive()
tag = tag_builder.CommitNew();
return true;
}
+
+bool
+DetachedSong::Update()
+{
+ if (IsAbsoluteFile()) {
+ const AllocatedPath path_fs =
+ AllocatedPath::FromUTF8(uri.c_str());
+
+ struct stat st;
+ if (!StatFile(path_fs, st) || !S_ISREG(st.st_mode))
+ return false;
+
+ TagBuilder tag_builder;
+ if (!tag_file_scan(path_fs, full_tag_handler, &tag_builder))
+ return false;
+
+ if (tag_builder.IsEmpty())
+ tag_scan_fallback(path_fs, &full_tag_handler,
+ &tag_builder);
+
+ mtime = st.st_mtime;
+ tag_builder.Commit(tag);
+ return true;
+ } else if (IsRemote()) {
+ TagBuilder tag_builder;
+ if (!tag_stream_scan(uri.c_str(), full_tag_handler,
+ &tag_builder))
+ return false;
+
+ mtime = 0;
+ tag_builder.Commit(tag);
+ return true;
+ } else
+ // TODO: implement
+ return false;
+}