2012-06-13 22:07:15 +02:00
|
|
|
/*
|
2013-01-02 19:22:15 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2012-06-13 22:07:15 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h" /* must be first for large file support */
|
2013-01-02 19:22:15 +01:00
|
|
|
#include "UpdateContainer.hxx"
|
|
|
|
#include "UpdateInternal.hxx"
|
|
|
|
#include "UpdateDatabase.hxx"
|
2013-01-02 20:56:21 +01:00
|
|
|
#include "DatabaseLock.hxx"
|
2013-01-02 22:52:08 +01:00
|
|
|
#include "Directory.hxx"
|
2012-06-13 22:07:15 +02:00
|
|
|
#include "song.h"
|
|
|
|
#include "decoder_plugin.h"
|
2013-01-02 22:43:56 +01:00
|
|
|
#include "Mapper.hxx"
|
2013-01-17 00:56:57 +01:00
|
|
|
#include "Path.hxx"
|
2013-01-02 19:22:15 +01:00
|
|
|
|
|
|
|
extern "C" {
|
2012-06-13 22:07:15 +02:00
|
|
|
#include "tag_handler.h"
|
2013-01-02 19:22:15 +01:00
|
|
|
}
|
2012-06-13 22:07:15 +02:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the specified directory object if it does not exist already
|
|
|
|
* or if the #stat object indicates that it has been modified since
|
|
|
|
* the last update. Returns NULL when it exists already and is
|
|
|
|
* unmodified.
|
|
|
|
*
|
|
|
|
* The caller must lock the database.
|
|
|
|
*/
|
2013-01-02 23:06:20 +01:00
|
|
|
static Directory *
|
|
|
|
make_directory_if_modified(Directory *parent, const char *name,
|
2012-06-13 22:07:15 +02:00
|
|
|
const struct stat *st)
|
|
|
|
{
|
2013-01-02 23:06:20 +01:00
|
|
|
Directory *directory = parent->FindChild(name);
|
2012-06-13 22:07:15 +02:00
|
|
|
|
|
|
|
// directory exists already
|
|
|
|
if (directory != NULL) {
|
|
|
|
if (directory->mtime == st->st_mtime && !walk_discard) {
|
|
|
|
/* not modified */
|
|
|
|
db_unlock();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_directory(directory);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
2013-01-02 23:06:10 +01:00
|
|
|
directory = parent->MakeChild(name);
|
2012-06-13 22:07:15 +02:00
|
|
|
directory->mtime = st->st_mtime;
|
|
|
|
return directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-02 23:06:20 +01:00
|
|
|
update_container_file(Directory *directory,
|
2012-06-13 22:07:15 +02:00
|
|
|
const char *name,
|
|
|
|
const struct stat *st,
|
|
|
|
const struct decoder_plugin *plugin)
|
|
|
|
{
|
|
|
|
if (plugin->container_scan == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
db_lock();
|
2013-01-02 23:06:20 +01:00
|
|
|
Directory *contdir = make_directory_if_modified(directory, name, st);
|
2012-06-13 22:07:15 +02:00
|
|
|
if (contdir == NULL) {
|
|
|
|
/* not modified */
|
|
|
|
db_unlock();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
contdir->device = DEVICE_CONTAINER;
|
|
|
|
db_unlock();
|
|
|
|
|
2013-01-17 00:56:57 +01:00
|
|
|
const Path pathname = map_directory_child_fs(directory, name);
|
2012-06-13 22:07:15 +02:00
|
|
|
|
|
|
|
char *vtrack;
|
|
|
|
unsigned int tnum = 0;
|
2013-01-17 00:56:57 +01:00
|
|
|
while ((vtrack = plugin->container_scan(pathname.c_str(), ++tnum)) != NULL) {
|
2012-06-13 22:07:15 +02:00
|
|
|
struct song *song = song_file_new(vtrack, contdir);
|
|
|
|
|
|
|
|
// shouldn't be necessary but it's there..
|
|
|
|
song->mtime = st->st_mtime;
|
|
|
|
|
2013-01-17 00:56:57 +01:00
|
|
|
const Path child_path_fs =
|
|
|
|
map_directory_child_fs(contdir, vtrack);
|
2012-06-13 22:07:15 +02:00
|
|
|
|
|
|
|
song->tag = tag_new();
|
2013-01-17 00:56:57 +01:00
|
|
|
decoder_plugin_scan_file(plugin, child_path_fs.c_str(),
|
2012-06-13 22:07:15 +02:00
|
|
|
&add_tag_handler, song->tag);
|
|
|
|
|
|
|
|
db_lock();
|
2013-01-02 23:06:10 +01:00
|
|
|
contdir->AddSong(song);
|
2012-06-13 22:07:15 +02:00
|
|
|
db_unlock();
|
|
|
|
|
|
|
|
modified = true;
|
|
|
|
|
2013-01-02 23:06:10 +01:00
|
|
|
g_message("added %s/%s", directory->GetPath(), vtrack);
|
2012-06-13 22:07:15 +02:00
|
|
|
g_free(vtrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tnum == 1) {
|
|
|
|
db_lock();
|
|
|
|
delete_directory(contdir);
|
|
|
|
db_unlock();
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|