playlist: use g_file_test() instead of stat()
To find out whether a file exists, use g_file_test() instead of stat(), because it is more portable and easier to use.
This commit is contained in:
parent
80fa9183e4
commit
0c422838a8
@ -1202,14 +1202,13 @@ void shufflePlaylist(void)
|
|||||||
enum playlist_result savePlaylist(const char *utf8file)
|
enum playlist_result savePlaylist(const char *utf8file)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct stat sb;
|
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if (!is_valid_playlist_name(utf8file))
|
if (!is_valid_playlist_name(utf8file))
|
||||||
return PLAYLIST_RESULT_BAD_NAME;
|
return PLAYLIST_RESULT_BAD_NAME;
|
||||||
|
|
||||||
path = map_spl_utf8_to_fs(utf8file);
|
path = map_spl_utf8_to_fs(utf8file);
|
||||||
if (!stat(path, &sb)) {
|
if (g_file_test(path, G_FILE_TEST_EXISTS)) {
|
||||||
g_free(path);
|
g_free(path);
|
||||||
return PLAYLIST_RESULT_LIST_EXISTS;
|
return PLAYLIST_RESULT_LIST_EXISTS;
|
||||||
}
|
}
|
||||||
|
@ -386,12 +386,10 @@ spl_append_uri(const char *url, const char *utf8file)
|
|||||||
static enum playlist_result
|
static enum playlist_result
|
||||||
spl_rename_internal(const char *from_path_fs, const char *to_path_fs)
|
spl_rename_internal(const char *from_path_fs, const char *to_path_fs)
|
||||||
{
|
{
|
||||||
struct stat st;
|
if (!g_file_test(from_path_fs, G_FILE_TEST_IS_REGULAR))
|
||||||
|
|
||||||
if (stat(from_path_fs, &st) != 0)
|
|
||||||
return PLAYLIST_RESULT_NO_SUCH_LIST;
|
return PLAYLIST_RESULT_NO_SUCH_LIST;
|
||||||
|
|
||||||
if (stat(to_path_fs, &st) == 0)
|
if (g_file_test(to_path_fs, G_FILE_TEST_EXISTS))
|
||||||
return PLAYLIST_RESULT_LIST_EXISTS;
|
return PLAYLIST_RESULT_LIST_EXISTS;
|
||||||
|
|
||||||
if (rename(from_path_fs, to_path_fs) < 0)
|
if (rename(from_path_fs, to_path_fs) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user