diff options
Diffstat (limited to '')
-rw-r--r-- | src/SongUpdate.cxx | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index 0245b9117..cf90fb9a2 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -27,7 +27,7 @@ #include "util/Error.hxx" #include "fs/AllocatedPath.hxx" #include "fs/Traits.hxx" -#include "fs/FileSystem.hxx" +#include "fs/FileInfo.hxx" #include "decoder/DecoderList.hxx" #include "tag/Tag.hxx" #include "tag/TagBuilder.hxx" @@ -37,6 +37,10 @@ #include "TagFile.hxx" #include "TagStream.hxx" +#ifdef ENABLE_ARCHIVE +#include "TagArchive.hxx" +#endif + #include <assert.h> #include <string.h> #include <sys/stat.h> @@ -52,9 +56,13 @@ Song::LoadFile(Storage &storage, const char *path_utf8, Directory &parent) Song *song = NewFile(path_utf8, parent); //in archive ? - bool success = parent.device == DEVICE_INARCHIVE + bool success = +#ifdef ENABLE_ARCHIVE + parent.device == DEVICE_INARCHIVE ? song->UpdateFileInArchive(storage) - : song->UpdateFile(storage); + : +#endif + song->UpdateFile(storage); if (!success) { song->Free(); return nullptr; @@ -83,7 +91,7 @@ Song::UpdateFile(Storage &storage) { const auto &relative_uri = GetURI(); - FileInfo info; + StorageFileInfo info; if (!storage.GetInfo(relative_uri.c_str(), true, info, IgnoreError())) return false; @@ -113,6 +121,10 @@ Song::UpdateFile(Storage &storage) return true; } +#endif + +#ifdef ENABLE_ARCHIVE + bool Song::UpdateFileInArchive(const Storage &storage) { @@ -132,7 +144,7 @@ Song::UpdateFileInArchive(const Storage &storage) return false; TagBuilder tag_builder; - if (!tag_stream_scan(path_fs.c_str(), full_tag_handler, &tag_builder)) + if (!tag_archive_scan(path_fs, full_tag_handler, &tag_builder)) return false; tag_builder.Commit(tag); @@ -142,27 +154,35 @@ Song::UpdateFileInArchive(const Storage &storage) #endif bool +DetachedSong::LoadFile(Path path) +{ + FileInfo fi; + if (!GetFileInfo(path, fi) || !fi.IsRegular()) + return false; + + TagBuilder tag_builder; + if (!tag_file_scan(path, full_tag_handler, &tag_builder)) + return false; + + if (tag_builder.IsEmpty()) + tag_scan_fallback(path, &full_tag_handler, + &tag_builder); + + mtime = fi.GetModificationTime(); + 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)) + if (path_fs.IsNull()) 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; + return LoadFile(path_fs); } else if (IsRemote()) { TagBuilder tag_builder; if (!tag_stream_scan(uri.c_str(), full_tag_handler, |