Ejemplo n.º 1
0
char *
map_directory_child_fs(const struct directory *directory, const char *name)
{
	char *name_fs, *parent_fs, *path;

	assert(music_dir != NULL);

	/* check for invalid or unauthorized base names */
	if (*name == 0 || strchr(name, '/') != NULL ||
	    strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
		return NULL;

	parent_fs = map_directory_fs(directory);
	if (parent_fs == NULL)
		return NULL;

	name_fs = utf8_to_fs_charset(name);
	if (name_fs == NULL) {
		g_free(parent_fs);
		return NULL;
	}

	path = g_build_filename(parent_fs, name_fs, NULL);
	g_free(parent_fs);
	g_free(name_fs);

	return path;
}
Ejemplo n.º 2
0
char *
map_song_fs(const struct song *song)
{
	assert(song_is_file(song));

	if (song_in_database(song))
		return map_directory_child_fs(song->parent, song->uri);
	else
		return utf8_to_fs_charset(song->uri);
}
Ejemplo n.º 3
0
	directory_for_each_song_safe(song, ns, directory) {
		assert(song->parent == directory);

		char *name_fs = utf8_to_fs_charset(song->uri);
		if (exclude_list_check(exclude_list, name_fs)) {
			delete_song(directory, song);
			modified = true;
		}

		g_free(name_fs);
	}
Ejemplo n.º 4
0
void
playlist_print_uri(FILE *file, const char *uri)
{
	char *s;

	if (playlist_saveAbsolutePaths && !uri_has_scheme(uri) &&
	    !g_path_is_absolute(uri))
		s = map_uri_fs(uri);
	else
		s = utf8_to_fs_charset(uri);

	if (s != NULL) {
		fprintf(file, "%s\n", s);
		g_free(s);
	}
}
Ejemplo n.º 5
0
/* passed to songvec_for_each */
static int
delete_song_if_excluded(struct song *song, void *_data)
{
	GSList *exclude_list = _data;
	char *name_fs;

	assert(song->parent != NULL);

	name_fs = utf8_to_fs_charset(song->uri);
	if (exclude_list_check(exclude_list, name_fs)) {
		delete_song(song->parent, song);
		modified = true;
	}

	g_free(name_fs);
	return 0;
}
Ejemplo n.º 6
0
static void
remove_excluded_from_directory(struct directory *directory,
			       GSList *exclude_list)
{
	db_lock();

	struct directory *child, *n;
	directory_for_each_child_safe(child, n, directory) {
		char *name_fs = utf8_to_fs_charset(directory_get_name(child));

		if (exclude_list_check(exclude_list, name_fs)) {
			delete_directory(child);
			modified = true;
		}

		g_free(name_fs);
	}
Ejemplo n.º 7
0
void
playlist_print_song(FILE *file, const struct song *song)
{
	if (playlist_saveAbsolutePaths && song_in_database(song)) {
		char *path = map_song_fs(song);
		if (path != NULL) {
			fprintf(file, "%s\n", path);
			g_free(path);
		}
	} else {
		char *uri = song_get_uri(song), *uri_fs;

		uri_fs = utf8_to_fs_charset(uri);
		g_free(uri);

		fprintf(file, "%s\n", uri_fs);
		g_free(uri_fs);
	}
}
Ejemplo n.º 8
0
char *
map_spl_utf8_to_fs(const char *name)
{
	char *filename_utf8, *filename_fs, *path;

	if (playlist_dir == NULL)
		return NULL;

	filename_utf8 = g_strconcat(name, PLAYLIST_FILE_SUFFIX, NULL);
	filename_fs = utf8_to_fs_charset(filename_utf8);
	g_free(filename_utf8);
	if (filename_fs == NULL)
		return NULL;

	path = g_build_filename(playlist_dir, filename_fs, NULL);
	g_free(filename_fs);

	return path;
}
Ejemplo n.º 9
0
char *
map_uri_fs(const char *uri)
{
	char *uri_fs, *path_fs;

	assert(uri != NULL);
	assert(*uri != '/');

	if (music_dir == NULL)
		return NULL;

	uri_fs = utf8_to_fs_charset(uri);
	if (uri_fs == NULL)
		return NULL;

	path_fs = g_build_filename(music_dir, uri_fs, NULL);
	g_free(uri_fs);

	return path_fs;
}
Ejemplo n.º 10
0
static void
remove_excluded_from_directory(struct directory *directory,
			       GSList *exclude_list)
{
	int i;
	struct dirvec *dv = &directory->children;

	for (i = dv->nr; --i >= 0; ) {
		struct directory *child = dv->base[i];
		char *name_fs = utf8_to_fs_charset(directory_get_name(child));

		if (exclude_list_check(exclude_list, name_fs)) {
			delete_directory(child);
			modified = true;
		}

		g_free(name_fs);
	}

	songvec_for_each(&directory->songs,
			 delete_song_if_excluded, exclude_list);
}