Index: playlist.c =================================================================== --- playlist.c (revision 22090) +++ playlist.c (working copy) @@ -3328,6 +3328,10 @@ if (format_track_path(path, filename, sizeof(tmp_buf), strlen(filename)+1, getcwd(NULL, -1)) < 0) return -1; + + /* in_ram buffer is unused for m3u files so we'll use for storing + updated indices */ + index_buf = (int*)playlist->buffer; if (!strncmp(playlist->filename, path, strlen(path))) { @@ -3340,9 +3344,6 @@ return -1; } - /* in_ram buffer is unused for m3u files so we'll use for storing - updated indices */ - index_buf = (int*)playlist->buffer; /* use temporary pathname */ snprintf(path, sizeof(path), "%s_temp", playlist->filename); @@ -3396,8 +3397,8 @@ break; } - if (overwrite_current) - index_buf[count] = lseek(fd, 0, SEEK_CUR); + //if (overwrite_current) + index_buf[count] = lseek(fd, 0, SEEK_CUR); if (fdprintf(fd, "%s\n", tmp_buf) < 0) { @@ -3421,43 +3422,78 @@ display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), true); close(fd); - - if (overwrite_current && result >= 0) + if(result >= 0) { result = -1; - mutex_lock(&playlist->control_mutex); - /* Replace the current playlist with the new one and update indices */ - close(playlist->fd); - if (remove(playlist->filename) >= 0) + if (overwrite_current) { - if (rename(path, playlist->filename) >= 0) + + + /* Replace the current playlist with the new one and update indices */ + close(playlist->fd); + if (remove(playlist->filename) >= 0) { - playlist->fd = open_utf8(playlist->filename, O_RDONLY); - if (playlist->fd >= 0) + if (rename(path, playlist->filename) >= 0) { - index = playlist->first_index; - for (i=0, count=0; iamount; i++) + playlist->fd = open_utf8(playlist->filename, O_RDONLY); + if (playlist->fd >= 0) { - if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK)) + index = playlist->first_index; + for (i=0, count=0; iamount; i++) { - playlist->indices[index] = index_buf[count]; - count++; + if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK)) + { + playlist->indices[index] = index_buf[count]; + count++; + } + index = (index+1)%playlist->amount; } - index = (index+1)%playlist->amount; + + /* we need to recreate control because inserted tracks are + now part of the playlist and shuffle has been + invalidated */ + result = recreate_control(playlist); } + } + } + } + else + { + /* Update indices and start using saved playlist file. */ + if(playlist->fd >= 0) + close(playlist->fd); + strcpy(playlist->filename,path); - /* we need to recreate control because inserted tracks are - now part of the playlist and shuffle has been - invalidated */ - result = recreate_control(playlist); + i= strlen(path); + while(path[i] != '/') + i--; + + playlist->dirlen = i+1; + + playlist->fd = open_utf8(playlist->filename, O_RDONLY); + if (playlist->fd >= 0) + { + index = playlist->first_index; + for (i=0, count=0; iamount; i++) + { + if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK)) + { + playlist->indices[index] = index_buf[count]; + count++; + } + index = (index+1)%playlist->amount; } + + /* we need to recreate control because inserted tracks are + now part of the playlist and shuffle has been + invalidated */ + result = recreate_control(playlist); } - } - - mutex_unlock(&playlist->control_mutex); - + + } + mutex_unlock(&playlist->control_mutex); } cpu_boost(false);