コード例 #1
0
ファイル: song_update.c プロジェクト: GunioRobot/mpd
struct song *
song_file_load(const char *path, struct directory *parent)
{
	struct song *song;
	bool ret;

	assert((parent == NULL) == g_path_is_absolute(path));
	assert(!uri_has_scheme(path));
	assert(strchr(path, '\n') == NULL);

	song = song_file_new(path, parent);

	//in archive ?
	if (parent != NULL && parent->device == DEVICE_INARCHIVE) {
		ret = song_file_update_inarchive(song);
	} else {
		ret = song_file_update(song);
	}
	if (!ret) {
		song_free(song);
		return NULL;
	}

	return song;
}
コード例 #2
0
static void
update_regular_file(struct directory *directory,
		    const char *name, const struct stat *st)
{
	const char *suffix = uri_get_suffix(name);
	const struct decoder_plugin* plugin;
#ifdef ENABLE_ARCHIVE
	const struct archive_plugin *archive;
#endif
	if (suffix == NULL)
		return;

	if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL)
	{
		struct song* song = songvec_find(&directory->songs, name);

		if (!(song != NULL && st->st_mtime == song->mtime &&
		      !walk_discard) &&
			plugin->container_scan != NULL)
		{
			if (update_container_file(directory, name, st, plugin))
			{
				if (song != NULL)
					delete_song(directory, song);

				return;
			}
		}

		if (song == NULL) {
			song = song_file_load(name, directory);
			if (song == NULL) {
				g_debug("ignoring unrecognized file %s/%s",
					directory_get_path(directory), name);
				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 || walk_discard) {
			g_message("updating %s/%s",
				  directory_get_path(directory), name);
			if (!song_file_update(song)) {
				g_debug("deleting unrecognized file %s/%s",
					directory_get_path(directory), name);
				delete_song(directory, song);
			}

			modified = true;
		}
#ifdef ENABLE_ARCHIVE
	} else if ((archive = archive_plugin_from_suffix(suffix))) {
		update_archive_file(directory, name, st, archive);
#endif
	}
}
コード例 #3
0
ファイル: update_song.c プロジェクト: lintweaker/mpd-dsd
static void
update_song_file2(struct directory *directory,
		  const char *name, const struct stat *st,
		  const struct decoder_plugin *plugin)
{
	db_lock();
	struct song *song = directory_get_song(directory, name);
	db_unlock();

	if (!directory_child_access(directory, name, R_OK)) {
		g_warning("no read permissions on %s/%s",
			  directory_get_path(directory), name);
		if (song != NULL) {
			db_lock();
			delete_song(directory, song);
			db_unlock();
		}

		return;
	}

	if (!(song != NULL && st->st_mtime == song->mtime &&
	      !walk_discard) &&
	    update_container_file(directory, name, st, plugin)) {
		if (song != NULL) {
			db_lock();
			delete_song(directory, song);
			db_unlock();
		}

		return;
	}

	if (song == NULL) {
		g_debug("reading %s/%s",
			directory_get_path(directory), name);
		song = song_file_load(name, directory);
		if (song == NULL) {
			g_debug("ignoring unrecognized file %s/%s",
				directory_get_path(directory), name);
			return;
		}

		db_lock();
		directory_add_song(directory, song);
		db_unlock();

		modified = true;
		g_message("added %s/%s",
			  directory_get_path(directory), name);
	} else if (st->st_mtime != song->mtime || walk_discard) {
		g_message("updating %s/%s",
			  directory_get_path(directory), name);
		if (!song_file_update(song)) {
			g_debug("deleting unrecognized file %s/%s",
				directory_get_path(directory), name);
			db_lock();
			delete_song(directory, song);
			db_unlock();
		}

		modified = true;
	}
}