diff options
Diffstat (limited to '')
-rw-r--r-- | src/SongUpdate.cxx | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index 1a873fedc..0f3e9b172 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.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 @@ -18,45 +18,40 @@ */ #include "config.h" /* must be first for large file support */ -#include "Song.hxx" +#include "DetachedSong.hxx" +#include "db/Song.hxx" +#include "db/Directory.hxx" #include "util/UriUtil.hxx" -#include "util/Error.hxx" -#include "Directory.hxx" #include "Mapper.hxx" #include "fs/AllocatedPath.hxx" #include "fs/Traits.hxx" #include "fs/FileSystem.hxx" -#include "InputStream.hxx" -#include "DecoderPlugin.hxx" -#include "DecoderList.hxx" +#include "decoder/DecoderList.hxx" #include "tag/Tag.hxx" #include "tag/TagBuilder.hxx" #include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" #include "tag/ApeTag.hxx" #include "TagFile.hxx" -#include "thread/Cond.hxx" +#include "TagStream.hxx" #include <assert.h> #include <string.h> -#include <sys/types.h> #include <sys/stat.h> -#include <stdio.h> Song * -Song::LoadFile(const char *path_utf8, Directory *parent) +Song::LoadFile(const char *path_utf8, Directory &parent) { Song *song; bool ret; - assert((parent == nullptr) == PathTraits::IsAbsoluteUTF8(path_utf8)); assert(!uri_has_scheme(path_utf8)); assert(strchr(path_utf8, '\n') == nullptr); song = NewFile(path_utf8, parent); //in archive ? - if (parent != nullptr && parent->device == DEVICE_INARCHIVE) { + if (parent.device == DEVICE_INARCHIVE) { ret = song->UpdateFileInArchive(); } else { ret = song->UpdateFile(); @@ -83,8 +78,6 @@ tag_scan_fallback(Path path, bool Song::UpdateFile() { - assert(IsFile()); - const auto path_fs = map_song_fs(*this); if (path_fs.IsNull()) return false; @@ -95,7 +88,7 @@ Song::UpdateFile() TagBuilder tag_builder; if (!tag_file_scan(path_fs, - &full_tag_handler, &tag_builder)) + full_tag_handler, &tag_builder)) return false; if (tag_builder.IsEmpty()) @@ -104,35 +97,66 @@ Song::UpdateFile() mtime = st.st_mtime; - delete tag; - tag = tag_builder.Commit(); + tag_builder.Commit(tag); return true; } bool Song::UpdateFileInArchive() { - const char *suffix; - const struct DecoderPlugin *plugin; - - assert(IsFile()); - /* check if there's a suffix and a plugin */ - suffix = uri_get_suffix(uri); + const char *suffix = uri_get_suffix(uri); if (suffix == nullptr) return false; - plugin = decoder_plugin_from_suffix(suffix, nullptr); - if (plugin == nullptr) + if (!decoder_plugins_supports_suffix(suffix)) return false; - delete tag; + const auto path_fs = map_song_fs(*this); + if (path_fs.IsNull()) + return false; - //accept every file that has music suffix - //because we don't support tag reading through - //input streams - tag = new Tag(); + TagBuilder tag_builder; + if (!tag_stream_scan(path_fs.c_str(), full_tag_handler, &tag_builder)) + return false; + tag_builder.Commit(tag); return true; } + +bool +DetachedSong::Update() +{ + if (IsAbsoluteFile()) { + const AllocatedPath path_fs = + AllocatedPath::FromUTF8(GetRealURI()); + + 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; +} |