2009-03-13 18:43:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
|
|
|
* http://www.musicpd.org
|
2008-10-08 10:48:48 +02:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-10-08 10:48:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "update.h"
|
2008-10-08 11:07:35 +02:00
|
|
|
#include "database.h"
|
2008-10-08 10:49:05 +02:00
|
|
|
#include "directory.h"
|
2008-10-08 10:49:11 +02:00
|
|
|
#include "song.h"
|
2009-02-25 16:44:06 +01:00
|
|
|
#include "uri.h"
|
2008-10-14 11:10:49 +02:00
|
|
|
#include "mapper.h"
|
2008-10-08 10:48:48 +02:00
|
|
|
#include "path.h"
|
2009-01-04 17:26:22 +01:00
|
|
|
#include "decoder_list.h"
|
2009-01-08 21:20:41 +01:00
|
|
|
#include "archive_list.h"
|
2008-10-08 10:48:48 +02:00
|
|
|
#include "playlist.h"
|
2009-01-01 18:12:00 +01:00
|
|
|
#include "event_pipe.h"
|
2009-01-04 20:42:43 +01:00
|
|
|
#include "notify.h"
|
2008-10-08 10:48:48 +02:00
|
|
|
#include "update.h"
|
2008-10-14 22:38:14 +02:00
|
|
|
#include "idle.h"
|
2008-11-28 10:57:39 +01:00
|
|
|
#include "conf.h"
|
2009-01-04 20:30:27 +01:00
|
|
|
#include "stats.h"
|
2009-01-03 13:19:01 +01:00
|
|
|
#include "main.h"
|
2009-01-08 21:20:41 +01:00
|
|
|
#include "config.h"
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-19 19:01:34 +01:00
|
|
|
#ifdef ENABLE_SQLITE
|
2009-02-04 22:33:43 +01:00
|
|
|
#include "sticker.h"
|
2009-01-19 19:01:34 +01:00
|
|
|
#include "song_sticker.h"
|
|
|
|
#endif
|
|
|
|
|
2008-10-20 22:18:12 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
2009-01-02 17:22:56 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2008-12-29 17:28:32 +01:00
|
|
|
|
2009-03-08 20:16:53 +01:00
|
|
|
#include "decoder_plugin.h"
|
|
|
|
|
2008-12-29 17:29:49 +01:00
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "update"
|
|
|
|
|
2008-10-09 19:31:31 +02:00
|
|
|
static enum update_progress {
|
2008-10-08 10:48:48 +02:00
|
|
|
UPDATE_PROGRESS_IDLE = 0,
|
|
|
|
UPDATE_PROGRESS_RUNNING = 1,
|
|
|
|
UPDATE_PROGRESS_DONE = 2
|
|
|
|
} progress;
|
|
|
|
|
2008-10-09 19:41:58 +02:00
|
|
|
static bool modified;
|
|
|
|
|
2008-10-08 10:48:48 +02:00
|
|
|
/* make this dynamic?, or maybe this is big enough... */
|
|
|
|
static char *update_paths[32];
|
|
|
|
static size_t update_paths_nr;
|
|
|
|
|
2008-12-28 22:09:42 +01:00
|
|
|
static GThread *update_thr;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-09 19:20:05 +02:00
|
|
|
static const unsigned update_task_id_max = 1 << 15;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-09 19:20:05 +02:00
|
|
|
static unsigned update_task_id;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
static struct song *delete;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-04 20:42:43 +01:00
|
|
|
/** used by the main thread to notify the update thread */
|
|
|
|
static struct notify update_notify;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-03 13:19:58 +01:00
|
|
|
#ifndef WIN32
|
|
|
|
|
2008-11-28 10:57:39 +01:00
|
|
|
enum {
|
|
|
|
DEFAULT_FOLLOW_INSIDE_SYMLINKS = true,
|
2008-12-08 09:00:38 +01:00
|
|
|
DEFAULT_FOLLOW_OUTSIDE_SYMLINKS = true,
|
2008-11-28 10:57:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool follow_inside_symlinks;
|
|
|
|
static bool follow_outside_symlinks;
|
|
|
|
|
2009-01-03 13:19:58 +01:00
|
|
|
#endif
|
|
|
|
|
2008-10-09 19:20:05 +02:00
|
|
|
unsigned
|
|
|
|
isUpdatingDB(void)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
return (progress != UPDATE_PROGRESS_IDLE) ? update_task_id : 0;
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static void
|
|
|
|
directory_set_stat(struct directory *dir, const struct stat *st)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
dir->inode = st->st_ino;
|
|
|
|
dir->device = st->st_dev;
|
|
|
|
dir->stat = 1;
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static void
|
2008-10-08 10:49:11 +02:00
|
|
|
delete_song(struct directory *dir, struct song *del)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
/* first, prevent traversers in main task from getting this */
|
|
|
|
songvec_delete(&dir->songs, del);
|
|
|
|
|
|
|
|
/* now take it out of the playlist (in the main_task) */
|
|
|
|
assert(!delete);
|
|
|
|
delete = del;
|
2009-01-01 18:22:11 +01:00
|
|
|
event_pipe_emit(PIPE_EVENT_DELETE);
|
2009-01-04 20:42:43 +01:00
|
|
|
|
|
|
|
do {
|
|
|
|
notify_wait(&update_notify);
|
|
|
|
} while (delete != NULL);
|
2008-10-08 10:48:48 +02:00
|
|
|
|
|
|
|
/* finally, all possible references gone, free it */
|
2008-10-08 11:05:34 +02:00
|
|
|
song_free(del);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 15:41:02 +02:00
|
|
|
static int
|
2008-11-24 14:46:10 +01:00
|
|
|
delete_each_song(struct song *song, G_GNUC_UNUSED void *data)
|
2008-10-09 15:41:02 +02:00
|
|
|
{
|
|
|
|
struct directory *directory = data;
|
|
|
|
assert(song->parent == directory);
|
|
|
|
delete_song(directory, song);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-12 19:11:26 +01:00
|
|
|
static void
|
|
|
|
delete_directory(struct directory *directory);
|
|
|
|
|
2008-10-09 15:41:02 +02:00
|
|
|
/**
|
|
|
|
* Recursively remove all sub directories and songs from a directory,
|
|
|
|
* leaving an empty directory.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
clear_directory(struct directory *directory)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = directory->children.nr; --i >= 0;)
|
2009-02-12 19:11:26 +01:00
|
|
|
delete_directory(directory->children.base[i]);
|
|
|
|
|
|
|
|
assert(directory->children.nr == 0);
|
2008-10-09 15:41:02 +02:00
|
|
|
|
|
|
|
songvec_for_each(&directory->songs, delete_each_song, directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively free a directory and all its contents.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
delete_directory(struct directory *directory)
|
|
|
|
{
|
|
|
|
assert(directory->parent != NULL);
|
|
|
|
|
|
|
|
clear_directory(directory);
|
|
|
|
|
|
|
|
dirvec_delete(&directory->parent->children, directory);
|
|
|
|
directory_free(directory);
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:46:32 +02:00
|
|
|
static void
|
|
|
|
delete_name_in(struct directory *parent, const char *name)
|
|
|
|
{
|
|
|
|
struct directory *directory = directory_get_child(parent, name);
|
|
|
|
struct song *song = songvec_find(&parent->songs, name);
|
|
|
|
|
|
|
|
if (directory != NULL) {
|
|
|
|
delete_directory(directory);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (song != NULL) {
|
|
|
|
delete_song(parent, song);
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:48:48 +02:00
|
|
|
/* passed to songvec_for_each */
|
2008-10-08 10:49:11 +02:00
|
|
|
static int
|
|
|
|
delete_song_if_removed(struct song *song, void *_data)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2009-01-04 17:28:34 +01:00
|
|
|
struct directory *dir = _data;
|
2009-01-02 10:48:55 +01:00
|
|
|
char *path;
|
2008-10-14 11:10:49 +02:00
|
|
|
struct stat st;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-02 10:48:55 +01:00
|
|
|
if ((path = map_song_fs(song)) == NULL ||
|
|
|
|
stat(path, &st) < 0 || !S_ISREG(st.st_mode)) {
|
2009-01-04 17:28:34 +01:00
|
|
|
delete_song(dir, song);
|
2008-10-09 19:41:58 +02:00
|
|
|
modified = true;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
2009-01-02 10:48:55 +01:00
|
|
|
|
|
|
|
g_free(path);
|
2008-10-08 10:48:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-04 17:26:07 +01:00
|
|
|
static bool
|
|
|
|
directory_exists(const struct directory *directory)
|
|
|
|
{
|
|
|
|
char *path_fs;
|
2009-02-28 14:02:08 +01:00
|
|
|
GFileTest test;
|
2009-01-04 17:26:07 +01:00
|
|
|
bool exists;
|
|
|
|
|
|
|
|
path_fs = map_directory_fs(directory);
|
|
|
|
if (path_fs == NULL)
|
|
|
|
/* invalid path: cannot exist */
|
|
|
|
return false;
|
|
|
|
|
2009-03-08 20:16:53 +01:00
|
|
|
test = directory->device == DEVICE_INARCHIVE ||
|
|
|
|
directory->device == DEVICE_CONTAINER
|
2009-02-28 14:02:08 +01:00
|
|
|
? G_FILE_TEST_IS_REGULAR
|
|
|
|
: G_FILE_TEST_IS_DIR;
|
|
|
|
|
|
|
|
exists = g_file_test(path_fs, test);
|
2009-01-04 17:26:07 +01:00
|
|
|
g_free(path_fs);
|
|
|
|
|
|
|
|
return exists;
|
|
|
|
}
|
|
|
|
|
2008-10-09 19:41:58 +02:00
|
|
|
static void
|
2009-01-02 10:48:55 +01:00
|
|
|
removeDeletedFromDirectory(struct directory *directory)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct dirvec *dv = &directory->children;
|
|
|
|
|
|
|
|
for (i = dv->nr; --i >= 0; ) {
|
2009-01-04 17:26:07 +01:00
|
|
|
if (directory_exists(dv->base[i]))
|
2009-01-02 10:48:11 +01:00
|
|
|
continue;
|
|
|
|
|
2008-12-29 17:29:49 +01:00
|
|
|
g_debug("removing directory: %s", dv->base[i]->path);
|
2009-02-12 18:57:12 +01:00
|
|
|
delete_directory(dv->base[i]);
|
2008-10-09 19:41:58 +02:00
|
|
|
modified = true;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2009-01-04 17:28:34 +01:00
|
|
|
songvec_for_each(&directory->songs, delete_song_if_removed, directory);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-14 11:10:49 +02:00
|
|
|
static int
|
|
|
|
stat_directory(const struct directory *directory, struct stat *st)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2009-01-02 10:48:11 +01:00
|
|
|
char *path_fs;
|
|
|
|
int ret;
|
2008-10-14 11:10:49 +02:00
|
|
|
|
2009-01-02 10:48:11 +01:00
|
|
|
path_fs = map_directory_fs(directory);
|
2008-10-14 11:10:49 +02:00
|
|
|
if (path_fs == NULL)
|
|
|
|
return -1;
|
2009-01-02 10:48:11 +01:00
|
|
|
ret = stat(path_fs, st);
|
|
|
|
g_free(path_fs);
|
|
|
|
return ret;
|
2008-10-14 11:10:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stat_directory_child(const struct directory *parent, const char *name,
|
|
|
|
struct stat *st)
|
|
|
|
{
|
2009-01-02 10:48:55 +01:00
|
|
|
char *path_fs;
|
|
|
|
int ret;
|
2008-10-31 16:47:21 +01:00
|
|
|
|
2009-01-02 10:48:55 +01:00
|
|
|
path_fs = map_directory_child_fs(parent, name);
|
2008-10-31 16:47:21 +01:00
|
|
|
if (path_fs == NULL)
|
|
|
|
return -1;
|
2008-10-14 11:10:49 +02:00
|
|
|
|
2009-01-02 10:48:55 +01:00
|
|
|
ret = stat(path_fs, st);
|
|
|
|
g_free(path_fs);
|
|
|
|
return ret;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static int
|
|
|
|
statDirectory(struct directory *dir)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
2008-10-14 11:10:49 +02:00
|
|
|
if (stat_directory(dir, &st) < 0)
|
2008-10-08 10:48:48 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
directory_set_stat(dir, &st);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static int
|
|
|
|
inodeFoundInParent(struct directory *parent, ino_t inode, dev_t device)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
while (parent) {
|
|
|
|
if (!parent->stat && statDirectory(parent) < 0)
|
|
|
|
return -1;
|
|
|
|
if (parent->inode == inode && parent->device == device) {
|
2008-12-29 17:29:49 +01:00
|
|
|
g_debug("recursive directory found");
|
2008-10-08 10:48:48 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
parent = parent->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:46:51 +02:00
|
|
|
static struct directory *
|
|
|
|
make_subdir(struct directory *parent, const char *name)
|
|
|
|
{
|
|
|
|
struct directory *directory;
|
|
|
|
|
|
|
|
directory = directory_get_child(parent, name);
|
2008-10-13 16:55:54 +02:00
|
|
|
if (directory == NULL) {
|
2009-01-04 19:37:19 +01:00
|
|
|
char *path;
|
2008-10-13 16:55:54 +02:00
|
|
|
|
2009-01-04 19:08:52 +01:00
|
|
|
if (directory_is_root(parent))
|
2009-01-04 19:37:19 +01:00
|
|
|
path = NULL;
|
2008-10-13 16:55:54 +02:00
|
|
|
else
|
2009-01-04 19:37:19 +01:00
|
|
|
name = path = g_strconcat(directory_get_path(parent),
|
|
|
|
"/", name, NULL);
|
2008-10-13 16:55:54 +02:00
|
|
|
|
2009-01-04 19:37:19 +01:00
|
|
|
directory = directory_new_child(parent, name);
|
|
|
|
g_free(path);
|
2008-10-13 16:55:54 +02:00
|
|
|
}
|
2008-10-13 16:46:51 +02:00
|
|
|
|
|
|
|
return directory;
|
|
|
|
}
|
|
|
|
|
2008-12-27 14:33:41 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
2008-12-16 21:42:42 +01:00
|
|
|
static void
|
|
|
|
update_archive_tree(struct directory *directory, char *name)
|
|
|
|
{
|
|
|
|
struct directory *subdir;
|
|
|
|
struct song *song;
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
tmp = strchr(name, '/');
|
|
|
|
if (tmp) {
|
|
|
|
*tmp = 0;
|
|
|
|
//add dir is not there already
|
|
|
|
if ((subdir = dirvec_find(&directory->children, name)) == NULL) {
|
|
|
|
//create new directory
|
|
|
|
subdir = make_subdir(directory, name);
|
|
|
|
subdir->device = DEVICE_INARCHIVE;
|
|
|
|
}
|
|
|
|
//create directories first
|
|
|
|
update_archive_tree(subdir, tmp+1);
|
|
|
|
} else {
|
2008-12-28 19:03:00 +01:00
|
|
|
if (strlen(name) == 0) {
|
2008-12-29 17:29:49 +01:00
|
|
|
g_warning("archive returned directory only");
|
2008-12-28 19:03:00 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-12-16 21:42:42 +01:00
|
|
|
//add file
|
|
|
|
song = songvec_find(&directory->songs, name);
|
|
|
|
if (song == NULL) {
|
|
|
|
song = song_file_load(name, directory);
|
|
|
|
if (song != NULL) {
|
|
|
|
songvec_add(&directory->songs, song);
|
|
|
|
modified = true;
|
2008-12-29 17:29:49 +01:00
|
|
|
g_message("added %s/%s",
|
|
|
|
directory_get_path(directory), name);
|
2008-12-16 21:42:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 14:01:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the file listing from an archive file.
|
|
|
|
*
|
|
|
|
* @param parent the parent directory the archive file resides in
|
|
|
|
* @param name the UTF-8 encoded base name of the archive file
|
2009-02-28 14:02:00 +01:00
|
|
|
* @param st stat() information on the archive file
|
2009-02-28 14:01:33 +01:00
|
|
|
* @param plugin the archive plugin which fits this archive type
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_archive_file(struct directory *parent, const char *name,
|
2009-02-28 14:02:00 +01:00
|
|
|
const struct stat *st,
|
2009-02-28 14:01:33 +01:00
|
|
|
const struct archive_plugin *plugin)
|
|
|
|
{
|
|
|
|
char *path_fs;
|
|
|
|
struct archive_file *file;
|
|
|
|
struct directory *directory;
|
|
|
|
char *filepath;
|
|
|
|
|
2009-02-28 14:02:03 +01:00
|
|
|
directory = dirvec_find(&parent->children, name);
|
|
|
|
if (directory != NULL && directory->mtime == st->st_mtime)
|
|
|
|
/* MPD has already scanned the archive, and it hasn't
|
|
|
|
changed since - don't consider updating it */
|
|
|
|
return;
|
|
|
|
|
2009-02-28 14:01:33 +01:00
|
|
|
path_fs = map_directory_child_fs(parent, name);
|
|
|
|
|
|
|
|
/* open archive */
|
|
|
|
file = plugin->open(path_fs);
|
|
|
|
if (file == NULL) {
|
|
|
|
g_warning("unable to open archive %s", path_fs);
|
|
|
|
g_free(path_fs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_debug("archive %s opened", path_fs);
|
|
|
|
g_free(path_fs);
|
|
|
|
|
|
|
|
if (directory == NULL) {
|
|
|
|
g_debug("creating archive directory: %s", name);
|
|
|
|
directory = make_subdir(parent, name);
|
|
|
|
/* mark this directory as archive (we use device for
|
|
|
|
this) */
|
|
|
|
directory->device = DEVICE_INARCHIVE;
|
|
|
|
}
|
|
|
|
|
2009-02-28 14:02:00 +01:00
|
|
|
directory->mtime = st->st_mtime;
|
|
|
|
|
2009-02-28 14:01:33 +01:00
|
|
|
plugin->scan_reset(file);
|
|
|
|
|
|
|
|
while ((filepath = plugin->scan_next(file)) != NULL) {
|
|
|
|
/* split name into directory and file */
|
|
|
|
g_debug("adding archive file: %s", filepath);
|
|
|
|
update_archive_tree(directory, filepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin->close(file);
|
|
|
|
}
|
2008-12-27 14:33:41 +01:00
|
|
|
#endif
|
2008-12-16 21:42:42 +01:00
|
|
|
|
2009-03-10 22:09:00 +01:00
|
|
|
static bool
|
|
|
|
update_container_file( struct directory* directory,
|
|
|
|
const char* name,
|
|
|
|
const struct stat* st,
|
|
|
|
const struct decoder_plugin* plugin)
|
|
|
|
{
|
|
|
|
char* vtrack = NULL;
|
|
|
|
unsigned int tnum = 0;
|
2009-08-14 11:51:51 +02:00
|
|
|
char* pathname = map_directory_child_fs(directory, name);
|
2009-03-10 22:09:00 +01:00
|
|
|
struct directory* contdir = dirvec_find(&directory->children, name);
|
|
|
|
|
|
|
|
// directory exists already
|
|
|
|
if (contdir != NULL)
|
|
|
|
{
|
|
|
|
// modification time not eq. file mod. time
|
|
|
|
if (contdir->mtime != st->st_mtime)
|
|
|
|
{
|
|
|
|
g_message("removing container file: %s", pathname);
|
|
|
|
|
|
|
|
delete_directory(contdir);
|
|
|
|
contdir = NULL;
|
|
|
|
|
|
|
|
modified = true;
|
|
|
|
}
|
2009-08-14 11:51:51 +02:00
|
|
|
else {
|
|
|
|
g_free(pathname);
|
2009-03-10 22:09:00 +01:00
|
|
|
return true;
|
2009-08-14 11:51:51 +02:00
|
|
|
}
|
2009-03-10 22:09:00 +01:00
|
|
|
}
|
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
contdir = make_subdir(directory, name);
|
|
|
|
contdir->mtime = st->st_mtime;
|
|
|
|
contdir->device = DEVICE_CONTAINER;
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL)
|
|
|
|
{
|
|
|
|
struct song* song = song_file_new(vtrack, contdir);
|
|
|
|
if (song == NULL)
|
|
|
|
return true;
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
// shouldn't be necessary but it's there..
|
|
|
|
song->mtime = st->st_mtime;
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
song->tag = plugin->tag_dup(map_directory_child_fs(contdir, vtrack));
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
songvec_add(&contdir->songs, song);
|
|
|
|
song = NULL;
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
modified = true;
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
g_free(vtrack);
|
|
|
|
}
|
2009-03-10 22:09:00 +01:00
|
|
|
|
2009-08-14 11:51:51 +02:00
|
|
|
g_free(pathname);
|
|
|
|
|
2009-03-11 09:57:32 +01:00
|
|
|
if (tnum == 1)
|
|
|
|
{
|
|
|
|
delete_directory(contdir);
|
|
|
|
return false;
|
2009-03-10 22:09:00 +01:00
|
|
|
}
|
2009-03-11 09:57:32 +01:00
|
|
|
else
|
|
|
|
return true;
|
2009-03-10 22:09:00 +01:00
|
|
|
}
|
|
|
|
|
2008-10-09 19:41:58 +02:00
|
|
|
static void
|
2009-01-04 17:26:18 +01:00
|
|
|
update_regular_file(struct directory *directory,
|
|
|
|
const char *name, const struct stat *st)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2009-01-04 17:46:42 +01:00
|
|
|
const char *suffix = uri_get_suffix(name);
|
2009-03-08 20:16:53 +01:00
|
|
|
const struct decoder_plugin* plugin;
|
2009-01-08 21:20:41 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
|
|
|
const struct archive_plugin *archive;
|
|
|
|
#endif
|
2009-01-04 17:26:22 +01:00
|
|
|
if (suffix == NULL)
|
|
|
|
return;
|
2009-03-08 20:16:53 +01:00
|
|
|
|
2009-03-10 22:09:00 +01:00
|
|
|
if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL)
|
|
|
|
{
|
|
|
|
struct song* song = songvec_find(&directory->songs, name);
|
|
|
|
|
2009-08-19 21:21:29 +02:00
|
|
|
if (!(song != NULL && st->st_mtime == song->mtime) &&
|
|
|
|
plugin->container_scan != NULL)
|
2009-03-08 20:16:53 +01:00
|
|
|
{
|
2009-03-10 22:09:00 +01:00
|
|
|
if (update_container_file(directory, name, st, plugin))
|
2009-03-08 20:16:53 +01:00
|
|
|
{
|
2009-03-10 22:09:00 +01:00
|
|
|
if (song != NULL)
|
2009-03-09 15:10:54 +01:00
|
|
|
delete_song(directory, song);
|
2009-03-08 20:16:53 +01:00
|
|
|
|
2009-03-10 22:09:00 +01:00
|
|
|
return;
|
2009-03-08 20:16:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 22:09:00 +01:00
|
|
|
if (song == NULL) {
|
|
|
|
song = song_file_load(name, directory);
|
|
|
|
if (song == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
songvec_add(&directory->songs, song);
|
|
|
|
modified = true;
|
|
|
|
g_message("added %s/%s",
|
|
|
|
directory_get_path(directory), name);
|
|
|
|
} else if (st->st_mtime != song->mtime) {
|
|
|
|
g_message("updating %s/%s",
|
|
|
|
directory_get_path(directory), name);
|
|
|
|
if (!song_file_update(song))
|
|
|
|
delete_song(directory, song);
|
|
|
|
modified = true;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
2008-12-27 14:33:41 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
2009-01-04 17:26:22 +01:00
|
|
|
} else if ((archive = archive_plugin_from_suffix(suffix))) {
|
2009-02-28 14:02:00 +01:00
|
|
|
update_archive_file(directory, name, st, archive);
|
2008-12-27 14:33:41 +01:00
|
|
|
#endif
|
2009-01-04 17:26:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
updateDirectory(struct directory *directory, const struct stat *st);
|
|
|
|
|
|
|
|
static void
|
|
|
|
updateInDirectory(struct directory *directory,
|
|
|
|
const char *name, const struct stat *st)
|
|
|
|
{
|
|
|
|
assert(strchr(name, '/') == NULL);
|
|
|
|
|
|
|
|
if (S_ISREG(st->st_mode)) {
|
|
|
|
update_regular_file(directory, name, st);
|
|
|
|
} else if (S_ISDIR(st->st_mode)) {
|
|
|
|
struct directory *subdir;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
if (inodeFoundInParent(directory, st->st_ino, st->st_dev))
|
|
|
|
return;
|
|
|
|
|
|
|
|
subdir = make_subdir(directory, name);
|
|
|
|
assert(directory == subdir->parent);
|
|
|
|
|
|
|
|
ret = updateDirectory(subdir, st);
|
|
|
|
if (!ret)
|
|
|
|
delete_directory(subdir);
|
2008-10-09 19:20:59 +02:00
|
|
|
} else {
|
2008-12-29 17:29:49 +01:00
|
|
|
g_debug("update: %s is not a directory, archive or music", name);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-15 20:51:01 +02:00
|
|
|
/* we don't look at "." / ".." nor files with newlines in their name */
|
|
|
|
static bool skip_path(const char *path)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2008-10-15 20:51:01 +02:00
|
|
|
return (path[0] == '.' && path[1] == 0) ||
|
|
|
|
(path[0] == '.' && path[1] == '.' && path[2] == 0) ||
|
|
|
|
strchr(path, '\n') != NULL;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-14 11:10:54 +02:00
|
|
|
static bool
|
|
|
|
skip_symlink(const struct directory *directory, const char *utf8_name)
|
|
|
|
{
|
2009-01-03 13:19:58 +01:00
|
|
|
#ifndef WIN32
|
2008-10-14 11:10:54 +02:00
|
|
|
char buffer[MPD_PATH_MAX];
|
2009-01-02 10:48:55 +01:00
|
|
|
char *path_fs;
|
2008-10-14 11:10:54 +02:00
|
|
|
const char *p;
|
|
|
|
ssize_t ret;
|
|
|
|
|
2009-01-02 10:48:55 +01:00
|
|
|
path_fs = map_directory_child_fs(directory, utf8_name);
|
|
|
|
if (path_fs == NULL)
|
2008-10-14 11:10:54 +02:00
|
|
|
return true;
|
|
|
|
|
2009-01-02 10:48:55 +01:00
|
|
|
ret = readlink(path_fs, buffer, sizeof(buffer));
|
|
|
|
g_free(path_fs);
|
2008-10-14 11:10:54 +02:00
|
|
|
if (ret < 0)
|
|
|
|
/* don't skip if this is not a symlink */
|
|
|
|
return errno != EINVAL;
|
|
|
|
|
2008-11-28 10:57:39 +01:00
|
|
|
if (!follow_inside_symlinks && !follow_outside_symlinks) {
|
|
|
|
/* ignore all symlinks */
|
|
|
|
return true;
|
|
|
|
} else if (follow_inside_symlinks && follow_outside_symlinks) {
|
|
|
|
/* consider all symlinks */
|
2008-10-14 11:10:54 +02:00
|
|
|
return false;
|
2008-11-28 10:57:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer[0] == '/')
|
|
|
|
return !follow_outside_symlinks;
|
2008-10-14 11:10:54 +02:00
|
|
|
|
|
|
|
p = buffer;
|
|
|
|
while (*p == '.') {
|
|
|
|
if (p[1] == '.' && p[2] == '/') {
|
|
|
|
/* "../" moves to parent directory */
|
|
|
|
directory = directory->parent;
|
2008-11-28 10:57:39 +01:00
|
|
|
if (directory == NULL) {
|
2008-10-14 11:10:54 +02:00
|
|
|
/* we have moved outside the music
|
2008-11-28 10:57:39 +01:00
|
|
|
directory - skip this symlink
|
|
|
|
if such symlinks are not allowed */
|
|
|
|
return !follow_outside_symlinks;
|
|
|
|
}
|
2008-10-14 11:10:54 +02:00
|
|
|
p += 3;
|
|
|
|
} else if (p[1] == '/')
|
|
|
|
/* eliminate "./" */
|
|
|
|
p += 2;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we are still in the music directory, so this symlink points
|
2008-11-28 10:57:39 +01:00
|
|
|
to a song which is already in the database - skip according
|
|
|
|
to the follow_inside_symlinks param*/
|
|
|
|
return !follow_inside_symlinks;
|
2009-01-03 13:19:58 +01:00
|
|
|
#else
|
|
|
|
/* no symlink checking on WIN32 */
|
|
|
|
|
|
|
|
(void)directory;
|
|
|
|
(void)utf8_name;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-10-14 11:10:54 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 19:41:58 +02:00
|
|
|
static bool
|
2008-10-09 19:13:03 +02:00
|
|
|
updateDirectory(struct directory *directory, const struct stat *st)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *ent;
|
2009-01-02 10:48:11 +01:00
|
|
|
char *path_fs;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-09 19:13:03 +02:00
|
|
|
assert(S_ISDIR(st->st_mode));
|
|
|
|
|
|
|
|
directory_set_stat(directory, st);
|
|
|
|
|
2009-01-02 10:48:11 +01:00
|
|
|
path_fs = map_directory_fs(directory);
|
2008-10-14 11:10:49 +02:00
|
|
|
if (path_fs == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dir = opendir(path_fs);
|
2009-02-27 09:05:58 +01:00
|
|
|
if (!dir) {
|
|
|
|
g_warning("Failed to open directory %s: %s",
|
|
|
|
path_fs, g_strerror(errno));
|
|
|
|
g_free(path_fs);
|
2008-10-09 19:41:58 +02:00
|
|
|
return false;
|
2009-02-27 09:05:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free(path_fs);
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-02 10:48:55 +01:00
|
|
|
removeDeletedFromDirectory(directory);
|
2008-10-08 10:48:48 +02:00
|
|
|
|
|
|
|
while ((ent = readdir(dir))) {
|
|
|
|
char *utf8;
|
2008-10-09 19:13:03 +02:00
|
|
|
struct stat st2;
|
|
|
|
|
2008-11-20 18:22:07 +01:00
|
|
|
if (skip_path(ent->d_name))
|
2008-10-08 10:48:48 +02:00
|
|
|
continue;
|
|
|
|
|
2009-01-08 21:20:46 +01:00
|
|
|
utf8 = fs_charset_to_utf8(ent->d_name);
|
|
|
|
if (utf8 == NULL || skip_symlink(directory, utf8)) {
|
|
|
|
g_free(utf8);
|
2008-10-08 10:48:48 +02:00
|
|
|
continue;
|
2009-01-08 21:20:46 +01:00
|
|
|
}
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-14 11:10:49 +02:00
|
|
|
if (stat_directory_child(directory, utf8, &st2) == 0)
|
2009-01-08 21:29:21 +01:00
|
|
|
updateInDirectory(directory, utf8, &st2);
|
2008-10-09 19:13:03 +02:00
|
|
|
else
|
2009-01-08 21:29:21 +01:00
|
|
|
delete_name_in(directory, utf8);
|
2009-01-08 21:20:46 +01:00
|
|
|
|
|
|
|
g_free(utf8);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
2009-02-28 14:02:00 +01:00
|
|
|
directory->mtime = st->st_mtime;
|
|
|
|
|
2008-10-09 19:41:58 +02:00
|
|
|
return true;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 15:47:22 +02:00
|
|
|
static struct directory *
|
|
|
|
directory_make_child_checked(struct directory *parent, const char *path)
|
|
|
|
{
|
|
|
|
struct directory *directory;
|
2008-11-22 14:57:08 +01:00
|
|
|
char *base;
|
2008-10-09 15:47:22 +02:00
|
|
|
struct stat st;
|
|
|
|
struct song *conflicting;
|
|
|
|
|
|
|
|
directory = directory_get_child(parent, path);
|
|
|
|
if (directory != NULL)
|
|
|
|
return directory;
|
|
|
|
|
2008-11-22 14:57:08 +01:00
|
|
|
base = g_path_get_basename(path);
|
2008-10-20 22:18:12 +02:00
|
|
|
|
2008-11-22 14:57:08 +01:00
|
|
|
if (stat_directory_child(parent, base, &st) < 0 ||
|
2008-10-20 22:18:12 +02:00
|
|
|
inodeFoundInParent(parent, st.st_ino, st.st_dev)) {
|
2008-11-22 14:57:08 +01:00
|
|
|
g_free(base);
|
2008-10-09 15:47:22 +02:00
|
|
|
return NULL;
|
2008-10-20 22:18:12 +02:00
|
|
|
}
|
2008-10-09 15:47:22 +02:00
|
|
|
|
|
|
|
/* if we're adding directory paths, make sure to delete filenames
|
|
|
|
with potentially the same name */
|
2008-11-22 14:57:08 +01:00
|
|
|
conflicting = songvec_find(&parent->songs, base);
|
2008-10-09 15:47:22 +02:00
|
|
|
if (conflicting)
|
|
|
|
delete_song(parent, conflicting);
|
|
|
|
|
2008-11-22 14:57:08 +01:00
|
|
|
g_free(base);
|
2008-10-20 22:18:12 +02:00
|
|
|
|
2008-10-09 19:14:04 +02:00
|
|
|
directory = directory_new_child(parent, path);
|
|
|
|
directory_set_stat(directory, &st);
|
|
|
|
return directory;
|
2008-10-09 15:47:22 +02:00
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:05 +02:00
|
|
|
static struct directory *
|
2008-10-09 15:48:39 +02:00
|
|
|
addParentPathToDB(const char *utf8path)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2008-10-09 15:48:07 +02:00
|
|
|
struct directory *directory = db_get_root();
|
2009-01-02 17:22:56 +01:00
|
|
|
char *duplicated = g_strdup(utf8path);
|
2008-10-09 15:48:07 +02:00
|
|
|
char *slash = duplicated;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-09 15:48:39 +02:00
|
|
|
while ((slash = strchr(slash, '/')) != NULL) {
|
|
|
|
*slash = 0;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-09 15:48:07 +02:00
|
|
|
directory = directory_make_child_checked(directory,
|
|
|
|
duplicated);
|
|
|
|
if (directory == NULL || slash == NULL)
|
|
|
|
break;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-09 15:48:07 +02:00
|
|
|
*slash++ = '/';
|
|
|
|
}
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-25 18:47:21 +01:00
|
|
|
g_free(duplicated);
|
2008-10-09 15:48:07 +02:00
|
|
|
return directory;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 19:41:58 +02:00
|
|
|
static void
|
|
|
|
updatePath(const char *path)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2008-10-13 16:55:55 +02:00
|
|
|
struct directory *parent;
|
2008-10-20 22:18:12 +02:00
|
|
|
char *name;
|
2008-10-09 19:13:02 +02:00
|
|
|
struct stat st;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-10-13 16:55:55 +02:00
|
|
|
parent = addParentPathToDB(path);
|
|
|
|
if (parent == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-10-20 22:18:12 +02:00
|
|
|
name = g_path_get_basename(path);
|
2008-10-13 16:55:55 +02:00
|
|
|
|
2008-10-14 11:10:49 +02:00
|
|
|
if (stat_directory_child(parent, name, &st) == 0)
|
2008-10-13 16:55:55 +02:00
|
|
|
updateInDirectory(parent, name, &st);
|
2008-10-09 19:41:58 +02:00
|
|
|
else
|
2008-10-13 16:55:55 +02:00
|
|
|
delete_name_in(parent, name);
|
2008-10-20 22:18:12 +02:00
|
|
|
|
|
|
|
g_free(name);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void * update_task(void *_path)
|
|
|
|
{
|
2008-10-09 19:11:49 +02:00
|
|
|
if (_path != NULL && !isRootDirectory(_path)) {
|
2008-10-09 19:41:58 +02:00
|
|
|
updatePath((char *)_path);
|
2008-10-08 10:48:48 +02:00
|
|
|
} else {
|
2008-10-09 19:13:03 +02:00
|
|
|
struct directory *directory = db_get_root();
|
|
|
|
struct stat st;
|
|
|
|
|
2008-10-14 11:10:49 +02:00
|
|
|
if (stat_directory(directory, &st) == 0)
|
2008-10-09 19:41:58 +02:00
|
|
|
updateDirectory(directory, &st);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2009-08-14 11:51:35 +02:00
|
|
|
g_free(_path);
|
|
|
|
|
2009-01-08 07:36:40 +01:00
|
|
|
if (modified || !db_exists())
|
2008-10-09 19:41:58 +02:00
|
|
|
db_save();
|
2009-01-08 07:36:40 +01:00
|
|
|
|
2008-10-08 10:48:48 +02:00
|
|
|
progress = UPDATE_PROGRESS_DONE;
|
2009-01-01 18:22:11 +01:00
|
|
|
event_pipe_emit(PIPE_EVENT_UPDATE);
|
2008-10-09 19:41:58 +02:00
|
|
|
return NULL;
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void spawn_update_task(char *path)
|
|
|
|
{
|
2009-01-04 19:51:54 +01:00
|
|
|
GError *e = NULL;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-12-28 22:09:42 +01:00
|
|
|
assert(g_thread_self() == main_task);
|
2008-10-08 10:48:48 +02:00
|
|
|
|
|
|
|
progress = UPDATE_PROGRESS_RUNNING;
|
2008-10-09 19:41:58 +02:00
|
|
|
modified = false;
|
2008-12-28 22:09:42 +01:00
|
|
|
if (!(update_thr = g_thread_create(update_task, path, TRUE, &e)))
|
2008-12-29 17:29:49 +01:00
|
|
|
g_error("Failed to spawn update task: %s", e->message);
|
2008-10-08 10:48:48 +02:00
|
|
|
if (++update_task_id > update_task_id_max)
|
|
|
|
update_task_id = 1;
|
2008-12-29 17:29:49 +01:00
|
|
|
g_debug("spawned thread for update job id %i", update_task_id);
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 19:20:05 +02:00
|
|
|
unsigned
|
2009-09-24 17:57:39 +02:00
|
|
|
update_enqueue(char *path)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2008-12-28 22:09:42 +01:00
|
|
|
assert(g_thread_self() == main_task);
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-18 16:56:07 +01:00
|
|
|
if (!mapper_has_music_directory())
|
|
|
|
return 0;
|
|
|
|
|
2008-10-08 10:48:48 +02:00
|
|
|
if (progress != UPDATE_PROGRESS_IDLE) {
|
2008-10-09 19:20:05 +02:00
|
|
|
unsigned next_task_id;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-02 17:22:56 +01:00
|
|
|
if (update_paths_nr == G_N_ELEMENTS(update_paths)) {
|
2009-01-25 18:47:21 +01:00
|
|
|
g_free(path);
|
2008-10-09 19:17:44 +02:00
|
|
|
return 0;
|
2008-10-09 19:20:54 +02:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:22:56 +01:00
|
|
|
assert(update_paths_nr < G_N_ELEMENTS(update_paths));
|
2008-10-08 10:48:48 +02:00
|
|
|
update_paths[update_paths_nr++] = path;
|
|
|
|
next_task_id = update_task_id + update_paths_nr;
|
|
|
|
|
|
|
|
return next_task_id > update_task_id_max ? 1 : next_task_id;
|
|
|
|
}
|
|
|
|
spawn_update_task(path);
|
2009-07-05 08:46:53 +02:00
|
|
|
|
|
|
|
idle_add(IDLE_UPDATE);
|
|
|
|
|
2008-10-08 10:48:48 +02:00
|
|
|
return update_task_id;
|
|
|
|
}
|
|
|
|
|
2009-01-04 20:30:23 +01:00
|
|
|
/**
|
|
|
|
* Safely delete a song from the database. This must be done in the
|
|
|
|
* main task, to be sure that there is no pointer left to it.
|
|
|
|
*/
|
|
|
|
static void song_delete_event(void)
|
2008-10-08 10:48:48 +02:00
|
|
|
{
|
2009-01-04 20:30:23 +01:00
|
|
|
char *uri;
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2009-01-04 20:30:23 +01:00
|
|
|
assert(progress == UPDATE_PROGRESS_RUNNING);
|
|
|
|
assert(delete != NULL);
|
2008-10-09 19:17:38 +02:00
|
|
|
|
2009-01-04 20:30:23 +01:00
|
|
|
uri = song_get_uri(delete);
|
|
|
|
g_debug("removing: %s", uri);
|
|
|
|
g_free(uri);
|
|
|
|
|
2009-01-19 19:01:34 +01:00
|
|
|
#ifdef ENABLE_SQLITE
|
|
|
|
/* if the song has a sticker, delete it */
|
2009-02-04 22:33:43 +01:00
|
|
|
if (sticker_enabled())
|
|
|
|
sticker_song_delete(delete);
|
2009-01-19 19:01:34 +01:00
|
|
|
#endif
|
|
|
|
|
2009-07-14 21:28:36 +02:00
|
|
|
playlist_delete_song(&g_playlist, delete);
|
2009-01-04 20:30:23 +01:00
|
|
|
delete = NULL;
|
|
|
|
|
2009-01-04 20:42:43 +01:00
|
|
|
notify_signal(&update_notify);
|
2009-01-04 20:30:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called in the main thread after the database update is finished.
|
|
|
|
*/
|
|
|
|
static void update_finished_event(void)
|
|
|
|
{
|
|
|
|
assert(progress == UPDATE_PROGRESS_DONE);
|
2008-10-08 10:48:48 +02:00
|
|
|
|
2008-12-28 22:09:42 +01:00
|
|
|
g_thread_join(update_thr);
|
2008-10-09 19:41:58 +02:00
|
|
|
|
2009-07-05 08:46:53 +02:00
|
|
|
idle_add(IDLE_UPDATE);
|
|
|
|
|
2008-10-14 22:38:14 +02:00
|
|
|
if (modified) {
|
2009-01-04 20:30:23 +01:00
|
|
|
/* send "idle" events */
|
2009-07-29 00:07:01 +02:00
|
|
|
playlist_increment_version_all(&g_playlist);
|
2008-10-14 22:38:14 +02:00
|
|
|
idle_add(IDLE_DATABASE);
|
|
|
|
}
|
2008-10-08 10:48:48 +02:00
|
|
|
|
|
|
|
if (update_paths_nr) {
|
2009-01-04 20:30:23 +01:00
|
|
|
/* schedule the next path */
|
2008-10-08 10:48:48 +02:00
|
|
|
char *path = update_paths[0];
|
|
|
|
memmove(&update_paths[0], &update_paths[1],
|
|
|
|
--update_paths_nr * sizeof(char *));
|
|
|
|
spawn_update_task(path);
|
|
|
|
} else {
|
|
|
|
progress = UPDATE_PROGRESS_IDLE;
|
2009-01-04 20:30:27 +01:00
|
|
|
|
2009-01-04 20:57:06 +01:00
|
|
|
stats_update();
|
2008-10-08 10:48:48 +02:00
|
|
|
}
|
|
|
|
}
|
2008-11-27 19:34:54 +01:00
|
|
|
|
|
|
|
void update_global_init(void)
|
|
|
|
{
|
2009-01-03 13:19:58 +01:00
|
|
|
#ifndef WIN32
|
2008-11-28 10:57:39 +01:00
|
|
|
follow_inside_symlinks =
|
|
|
|
config_get_bool(CONF_FOLLOW_INSIDE_SYMLINKS,
|
|
|
|
DEFAULT_FOLLOW_INSIDE_SYMLINKS);
|
|
|
|
|
|
|
|
follow_outside_symlinks =
|
|
|
|
config_get_bool(CONF_FOLLOW_OUTSIDE_SYMLINKS,
|
|
|
|
DEFAULT_FOLLOW_OUTSIDE_SYMLINKS);
|
2009-01-03 13:19:58 +01:00
|
|
|
#endif
|
2008-12-28 22:09:42 +01:00
|
|
|
|
2009-01-04 20:42:43 +01:00
|
|
|
notify_init(&update_notify);
|
2009-01-01 18:22:11 +01:00
|
|
|
|
2009-01-04 20:30:23 +01:00
|
|
|
event_pipe_register(PIPE_EVENT_DELETE, song_delete_event);
|
|
|
|
event_pipe_register(PIPE_EVENT_UPDATE, update_finished_event);
|
2008-11-27 19:34:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_global_finish(void)
|
|
|
|
{
|
2009-01-04 20:42:43 +01:00
|
|
|
notify_deinit(&update_notify);
|
2008-11-27 19:34:54 +01:00
|
|
|
}
|