summaryrefslogtreecommitdiff
path: root/playlist.c
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-05-22 22:21:55 +0200
committerGravatar waker <wakeroid@gmail.com>2012-05-22 22:21:55 +0200
commitdf0232d67ee161abc1c1341856a2c5e60b9e568a (patch)
tree52ae43f2f5edf3f5df424117872f1b2e4890d6e5 /playlist.c
parent8e34cdbf453a70e720913c6346ece19598c3ba54 (diff)
implemented playlist saving as atomic operation; fixed few PATH_MAX definitions
Diffstat (limited to 'playlist.c')
-rw-r--r--playlist.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/playlist.c b/playlist.c
index 855486c6..3b957487 100644
--- a/playlist.c
+++ b/playlist.c
@@ -1864,10 +1864,12 @@ plt_save (playlist_t *plt, playItem_t *first, playItem_t *last, const char *fnam
}
}
+ char tempfile[PATH_MAX];
+ snprintf (tempfile, sizeof (tempfile), "%s.tmp", fname);
const char magic[] = "DBPL";
uint8_t majorver = PLAYLIST_MAJOR_VER;
uint8_t minorver = PLAYLIST_MINOR_VER;
- FILE *fp = fopen (fname, "w+b");
+ FILE *fp = fopen (tempfile, "w+b");
if (!fp) {
UNLOCK;
return -1;
@@ -2034,11 +2036,14 @@ plt_save (playlist_t *plt, playItem_t *first, playItem_t *last, const char *fnam
UNLOCK;
fclose (fp);
+ if (rename (tempfile, fname) != 0) {
+ fprintf (stderr, "playlist rename %s -> %s failed: %s\n", tempfile, fname, strerror (errno));
+ }
return 0;
save_fail:
UNLOCK;
fclose (fp);
- unlink (fname);
+ unlink (tempfile);
return -1;
}