summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--playlist.c78
-rw-r--r--playlist.h3
2 files changed, 51 insertions, 30 deletions
diff --git a/playlist.c b/playlist.c
index 095e1073..f2d07dd1 100644
--- a/playlist.c
+++ b/playlist.c
@@ -306,20 +306,13 @@ plt_add (int before, const char *title) {
fprintf (stderr, "playlist rename failed: %s\n", strerror (errno));
}
}
-#if 0
- // need to delete old playlist file if exists
- char path[PATH_MAX];
- if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, playlists_count-1) <= sizeof (path)) {
- unlink (path);
- }
-#endif
- pl_save_current ();
}
}
PLT_UNLOCK;
plt_gen_conf ();
if (!plt_loading) {
+ pl_save_n (before);
deadbeef->conf_save ();
plug_trigger_event (DB_EV_PLAYLISTSWITCH, 0);
}
@@ -543,17 +536,26 @@ plt_move (int from, int to) {
char temp[PATH_MAX];
if (snprintf (path1, sizeof (path1), "%s/playlists/%d.dbpl", dbconfdir, from) > sizeof (path1)) {
fprintf (stderr, "error: failed to make path string for playlist file\n");
+ PLT_UNLOCK;
return;
}
if (snprintf (temp, sizeof (temp), "%s/playlists/temp.dbpl", dbconfdir) > sizeof (temp)) {
fprintf (stderr, "error: failed to make path string for playlist file\n");
+ PLT_UNLOCK;
return;
}
- trace ("move %s->%s\n", path1, temp);
- int err = rename (path1, temp);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", path1, temp, strerror (errno));
- return;
+
+ struct stat st;
+ int err = stat (path1, &st);
+ if (!err) {
+ trace ("move %s->%s\n", path1, temp);
+
+ int err = rename (path1, temp);
+ if (err != 0) {
+ fprintf (stderr, "playlist rename %s->%s failed: %s\n", path1, temp, strerror (errno));
+ PLT_UNLOCK;
+ return;
+ }
}
// remove 'from' from list
@@ -584,10 +586,13 @@ plt_move (int from, int to) {
fprintf (stderr, "error: failed to make path string for playlist file\n");
continue;
}
- trace ("move %s->%s\n", path2, path1);
- int err = rename (path2, path1);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", path2, path1, strerror (errno));
+ int err = stat (path2, &st);
+ if (!err) {
+ trace ("move %s->%s\n", path2, path1);
+ int err = rename (path2, path1);
+ if (err != 0) {
+ fprintf (stderr, "playlist rename %s->%s failed: %s\n", path2, path1, strerror (errno));
+ }
}
}
// open new gap
@@ -602,10 +607,13 @@ plt_move (int from, int to) {
fprintf (stderr, "error: failed to make path string for playlist file\n");
continue;
}
- trace ("move %s->%s\n", path1, path2);
- int err = rename (path1, path2);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", path1, path2, strerror (errno));
+ int err = stat (path1, &st);
+ if (!err) {
+ trace ("move %s->%s\n", path1, path2);
+ int err = rename (path1, path2);
+ if (err != 0) {
+ fprintf (stderr, "playlist rename %s->%s failed: %s\n", path1, path2, strerror (errno));
+ }
}
}
// move temp file
@@ -613,10 +621,13 @@ plt_move (int from, int to) {
fprintf (stderr, "error: failed to make path string for playlist file\n");
}
else {
- trace ("move %s->%s\n", temp, path1);
- int err = rename (temp, path1);
- if (err != 0) {
- fprintf (stderr, "playlist rename %s->%s failed: %s\n", temp, path1, strerror (errno));
+ int err = stat (path1, &st);
+ if (!err) {
+ trace ("move %s->%s\n", temp, path1);
+ int err = rename (temp, path1);
+ if (err != 0) {
+ fprintf (stderr, "playlist rename %s->%s failed: %s\n", temp, path1, strerror (errno));
+ }
}
}
@@ -1931,7 +1942,7 @@ save_fail:
}
int
-pl_save_current (void) {
+pl_save_n (int n) {
char path[PATH_MAX];
if (snprintf (path, sizeof (path), "%s/playlists", dbconfdir) > sizeof (path)) {
fprintf (stderr, "error: failed to make path string for playlists folder\n");
@@ -1941,11 +1952,10 @@ pl_save_current (void) {
mkdir (path, 0755);
PLT_LOCK;
- int curr = plt_get_curr ();
int err = 0;
plt_loading = 1;
- if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, curr) > sizeof (path)) {
+ if (snprintf (path, sizeof (path), "%s/playlists/%d.dbpl", dbconfdir, n) > sizeof (path)) {
fprintf (stderr, "error: failed to make path string for playlist file\n");
PLT_UNLOCK;
return -1;
@@ -1957,6 +1967,11 @@ pl_save_current (void) {
}
int
+pl_save_current (void) {
+ return pl_save_n (plt_get_curr ());
+}
+
+int
pl_save_all (void) {
trace ("pl_save_all\n");
char path[PATH_MAX];
@@ -2233,10 +2248,13 @@ pl_load_all (void) {
}
else {
fprintf (stderr, "INFO: from file %s\n", path);
- err = pl_load (path);
+ int load_err = pl_load (path);
+ if (load_err != 0) {
+ fprintf (stderr, "WARNING: failed to load playlist '%s' (%s)\n", it->value, path);
+ }
}
it = conf_find ("playlist.tab.", it);
- fprintf (stderr, "conf_find returned %p\n", it);
+ trace ("conf_find returned %p (%s)\n", it, it ? it->value : "null");
i++;
}
plt_set_curr (0);
diff --git a/playlist.h b/playlist.h
index 8f57cc2b..c04fe11e 100644
--- a/playlist.h
+++ b/playlist.h
@@ -214,6 +214,9 @@ int
pl_save (const char *fname);
int
+pl_save_n (int n);
+
+int
pl_save_current (void);
int