mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 10:07:38 -04:00
playlist: use path_strip_last_volume, clarify path conventions
The comment regarding Windows paths was fairly confusing as to its intent. What the code is trying to do is replace the drive letter with the volume containing the playlist, which appears reasonable. The middle of the comment was devoted to explaining why the code below was potentially incorrect which only served to add to the confusion. AFAICT the last volume specifier in a path will cause search to start from the root of that volume, so any incorrect result can be avoided by using the new function path_strip_last_volume(). Finally, add a comment at the top of the function that explains what it does. Change-Id: If4e4938801f2f81eb52f5d32b5461872995e5e83
This commit is contained in:
parent
4f05a9d066
commit
5ffe520de4
1 changed files with 16 additions and 16 deletions
|
@ -1741,6 +1741,20 @@ static int check_subdir_for_music(char *dir, const char *subdir, bool recurse)
|
|||
|
||||
/*
|
||||
* Returns absolute path of track
|
||||
*
|
||||
* dest: output buffer
|
||||
* src: the file name from the playlist
|
||||
* dir: the absolute path to the directory where the playlist resides
|
||||
*
|
||||
* The type of path in "src" determines what will be written to "dest":
|
||||
*
|
||||
* 1. UNIX-style absolute paths (/foo/bar) remain unaltered
|
||||
* 2. Windows-style absolute paths (C:/foo/bar) will be converted into an
|
||||
* absolute path by replacing the drive letter with the volume that the
|
||||
* *playlist* resides on, ie. the volume in "dir"
|
||||
* 3. Relative paths are converted to absolute paths by prepending "dir".
|
||||
* This also applies to Windows-style relative paths "C:foo/bar" where
|
||||
* the drive letter is accepted but ignored.
|
||||
*/
|
||||
static ssize_t format_track_path(char *dest, char *src, int buf_length,
|
||||
const char *dir)
|
||||
|
@ -1770,27 +1784,13 @@ static ssize_t format_track_path(char *dest, char *src, int buf_length,
|
|||
/* Replace backslashes with forward slashes */
|
||||
path_correct_separators(src, src);
|
||||
|
||||
/* Drive letters have no meaning here; handle DOS style drive letter
|
||||
* and parse greedily so that:
|
||||
*
|
||||
* 1) "c:/foo" is fully qualified, use directory volume only
|
||||
* 2) "c:foo" is relative to current directory on C, use directory path
|
||||
*
|
||||
* Assume any volume on the beginning of the directory path is actually
|
||||
* the volume on which it resides. This may not be the case if the dir
|
||||
* param contains a path such as "/<1>/foo/../../<0>/bar", which refers
|
||||
* to "/<0>/bar" (aka "/bar" at this time). *fingers crossed*
|
||||
*
|
||||
* If any stripped drive spec was absolute, prepend the playlist
|
||||
* directory's volume spec, or root if none. Absolute UNIX-style paths
|
||||
* remain unaltered.
|
||||
*/
|
||||
/* Handle Windows-style absolute paths */
|
||||
if (path_strip_drive(src, (const char **)&src, true) >= 0 &&
|
||||
src[-1] == PATH_SEPCH)
|
||||
{
|
||||
#ifdef HAVE_MULTIVOLUME
|
||||
const char *p;
|
||||
path_strip_volume(dir, &p, false);
|
||||
path_strip_last_volume(dir, &p, false);
|
||||
dir = strmemdupa(dir, p - dir); /* empty if no volspec on dir */
|
||||
#else
|
||||
dir = ""; /* only volume is root */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue