2
* Copyright (C) 2003-2012 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#include "config.h" /* must be first for large file support */
21
#include "update_container.h"
22
#include "update_internal.h"
23
#include "update_db.h"
25
#include "directory.h"
28
#include "decoder_plugin.h"
30
#include "tag_handler.h"
35
* Create the specified directory object if it does not exist already
36
* or if the #stat object indicates that it has been modified since
37
* the last update. Returns NULL when it exists already and is
40
* The caller must lock the database.
42
static struct directory *
43
make_directory_if_modified(struct directory *parent, const char *name,
44
const struct stat *st)
46
struct directory *directory = directory_get_child(parent, name);
48
// directory exists already
49
if (directory != NULL) {
50
if (directory->mtime == st->st_mtime && !walk_discard) {
56
delete_directory(directory);
60
directory = directory_make_child(parent, name);
61
directory->mtime = st->st_mtime;
66
update_container_file(struct directory *directory,
68
const struct stat *st,
69
const struct decoder_plugin *plugin)
71
if (plugin->container_scan == NULL)
75
struct directory *contdir =
76
make_directory_if_modified(directory, name, st);
77
if (contdir == NULL) {
83
contdir->device = DEVICE_CONTAINER;
86
char *const pathname = map_directory_child_fs(directory, name);
89
unsigned int tnum = 0;
90
while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) {
91
struct song *song = song_file_new(vtrack, contdir);
93
// shouldn't be necessary but it's there..
94
song->mtime = st->st_mtime;
96
char *child_path_fs = map_directory_child_fs(contdir, vtrack);
98
song->tag = tag_new();
99
decoder_plugin_scan_file(plugin, child_path_fs,
100
&add_tag_handler, song->tag);
101
g_free(child_path_fs);
104
directory_add_song(contdir, song);
109
g_message("added %s/%s",
110
directory_get_path(directory), vtrack);
118
delete_directory(contdir);