summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-03-31 20:14:19 +0100
committerAidan MacDonald <amachronic@protonmail.com>2022-04-01 11:40:02 -0400
commit5ffe520de4c70cfabc67a329cdb77d3d997bd45a (patch)
tree509537d1b39d732091fc8b2aa2464c0fd10108c2
parent4f05a9d066337a883d8d82b531ff8db5c989e5b9 (diff)
downloadrockbox-5ffe520de4.tar.gz
rockbox-5ffe520de4.zip
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
-rw-r--r--apps/playlist.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 88a6869895..32b8383442 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -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 */