~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/update_container.c

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003-2012 The Music Player Daemon Project
3
 
 * http://www.musicpd.org
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 */
19
 
 
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"
24
 
#include "db_lock.h"
25
 
#include "directory.h"
26
 
#include "song.h"
27
 
#include "mapper.h"
28
 
#include "decoder_plugin.h"
29
 
#include "tag.h"
30
 
#include "tag_handler.h"
31
 
 
32
 
#include <glib.h>
33
 
 
34
 
/**
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
38
 
 * unmodified.
39
 
 *
40
 
 * The caller must lock the database.
41
 
 */
42
 
static struct directory *
43
 
make_directory_if_modified(struct directory *parent, const char *name,
44
 
                           const struct stat *st)
45
 
{
46
 
        struct directory *directory = directory_get_child(parent, name);
47
 
 
48
 
        // directory exists already
49
 
        if (directory != NULL) {
50
 
                if (directory->mtime == st->st_mtime && !walk_discard) {
51
 
                        /* not modified */
52
 
                        db_unlock();
53
 
                        return NULL;
54
 
                }
55
 
 
56
 
                delete_directory(directory);
57
 
                modified = true;
58
 
        }
59
 
 
60
 
        directory = directory_make_child(parent, name);
61
 
        directory->mtime = st->st_mtime;
62
 
        return directory;
63
 
}
64
 
 
65
 
bool
66
 
update_container_file(struct directory *directory,
67
 
                      const char *name,
68
 
                      const struct stat *st,
69
 
                      const struct decoder_plugin *plugin)
70
 
{
71
 
        if (plugin->container_scan == NULL)
72
 
                return false;
73
 
 
74
 
        db_lock();
75
 
        struct directory *contdir =
76
 
                make_directory_if_modified(directory, name, st);
77
 
        if (contdir == NULL) {
78
 
                /* not modified */
79
 
                db_unlock();
80
 
                return true;
81
 
        }
82
 
 
83
 
        contdir->device = DEVICE_CONTAINER;
84
 
        db_unlock();
85
 
 
86
 
        char *const pathname = map_directory_child_fs(directory, name);
87
 
 
88
 
        char *vtrack;
89
 
        unsigned int tnum = 0;
90
 
        while ((vtrack = plugin->container_scan(pathname, ++tnum)) != NULL) {
91
 
                struct song *song = song_file_new(vtrack, contdir);
92
 
 
93
 
                // shouldn't be necessary but it's there..
94
 
                song->mtime = st->st_mtime;
95
 
 
96
 
                char *child_path_fs = map_directory_child_fs(contdir, vtrack);
97
 
 
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);
102
 
 
103
 
                db_lock();
104
 
                directory_add_song(contdir, song);
105
 
                db_unlock();
106
 
 
107
 
                modified = true;
108
 
 
109
 
                g_message("added %s/%s",
110
 
                          directory_get_path(directory), vtrack);
111
 
                g_free(vtrack);
112
 
        }
113
 
 
114
 
        g_free(pathname);
115
 
 
116
 
        if (tnum == 1) {
117
 
                db_lock();
118
 
                delete_directory(contdir);
119
 
                db_unlock();
120
 
                return false;
121
 
        } else
122
 
                return true;
123
 
}