From d1fd4f08f56f6dd46b26b1f41baff425ca71d498 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 21 Jul 2011 06:40:21 +0000 Subject: Fix FS#8656 - Error saving non-current playlist file Use the plugin buffer to save the playlist copy if there isnt enough buffer already allocated to the inram copy of the playlist git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30184 a1c6a512-1295-4272-9138-f99709370657 --- apps/playlist.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'apps/playlist.c') diff --git a/apps/playlist.c b/apps/playlist.c index ae6ea900d2..367e935006 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -103,6 +103,7 @@ #include "splash.h" #include "rbunicode.h" #include "root_menu.h" +#include "plugin.h" /* To borrow a temp buffer to rewrite a .m3u8 file */ #define PLAYLIST_CONTROL_FILE_VERSION 2 @@ -3369,6 +3370,8 @@ int playlist_save(struct playlist_info* playlist, char *filename) int result = 0; bool overwrite_current = false; int* index_buf = NULL; + char* old_buffer = NULL; + size_t old_buffer_size = 0; if (!playlist) playlist = ¤t_playlist; @@ -3388,8 +3391,17 @@ int playlist_save(struct playlist_info* playlist, char *filename) if (playlist->buffer_size < (int)(playlist->amount * sizeof(int))) { /* not enough buffer space to store updated indices */ - splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR)); - return -1; + /* Try to get a buffer */ + old_buffer = playlist->buffer; + old_buffer_size = playlist->buffer_size; + playlist->buffer = plugin_get_buffer((size_t*)&playlist->buffer_size); + if (playlist->buffer_size < (int)(playlist->amount * sizeof(int))) + { + playlist->buffer = old_buffer; + playlist->buffer_size = old_buffer_size; + splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR)); + return -1; + } } /* in_ram buffer is unused for m3u files so we'll use for storing @@ -3413,6 +3425,11 @@ int playlist_save(struct playlist_info* playlist, char *filename) if (fd < 0) { splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR)); + if (old_buffer != NULL) + { + playlist->buffer = old_buffer; + playlist->buffer_size = old_buffer_size; + } return -1; } @@ -3513,6 +3530,11 @@ int playlist_save(struct playlist_info* playlist, char *filename) } cpu_boost(false); + if (old_buffer != NULL) + { + playlist->buffer = old_buffer; + playlist->buffer_size = old_buffer_size; + } return result; } -- cgit v1.2.3