summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDana Conrad <dconrad@fastmail.com>2024-12-05 01:54:01 +0000
committerSolomon Peachy <pizza@shaftnet.org>2024-12-17 21:18:06 -0500
commit7d3cc24dec12554d58f65db748a98c3f8bcba71b (patch)
tree9a012b5f06be48d3464a0660626d28890f9de5b5
parentaeb4b6c34a3c3c8286e447506f22e57718350e6a (diff)
downloadrockbox-7d3cc24dec.tar.gz
rockbox-7d3cc24dec.zip
FS#13519: multivolume: Ensure absolute paths get drive designation
Change-Id: I8419af670ca101b11bba29d9fd577f21fa22fd42
-rw-r--r--apps/playlist.c4
-rw-r--r--firmware/common/pathfuncs.c37
2 files changed, 36 insertions, 5 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 465ebb88a0..00343e839e 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -70,7 +70,7 @@
flushed to disk when required.
*/
-//#define LOGF_ENABLE
+// #define LOGF_ENABLE
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@@ -592,6 +592,8 @@ static ssize_t format_track_path(char *dest, char *src, int buf_length,
dlen = -1u;
}
+ logf("dir: %s", dir);
+
len = path_append_ex(dest, dir, dlen, src, buf_length);
if (len >= (size_t)buf_length)
return -1; /* buffer too small */
diff --git a/firmware/common/pathfuncs.c b/firmware/common/pathfuncs.c
index b5e5ecb0cf..ba815e3307 100644
--- a/firmware/common/pathfuncs.c
+++ b/firmware/common/pathfuncs.c
@@ -27,6 +27,9 @@
#include "file_internal.h"
#include "debug.h"
+// #define LOGF_ENABLE
+#include "logf.h"
+
#ifdef HAVE_MULTIVOLUME
#include "storage.h"
@@ -521,10 +524,36 @@ size_t path_append_ex(char *buf, const char *basepath, size_t basepath_max,
if (path_is_absolute(component)) /* starts with a '/' path separator */
{
- /* 'component' is absolute; replace all */
- basepath = component;
- component = "";
- basepath_max = -1u;
+ #if defined(HAVE_MULTIVOLUME)
+ const char *baseend;
+ /* our component doesn't appear to have a drive/volume */
+ if (path_strip_volume(component, &baseend, false) == ROOT_VOLUME)
+ {
+ /* find the basepath's drive/volume name, if it has one.
+ * ensure basepath is not NULL, that causes a crash on sim */
+ if (basepath != NULL && path_strip_volume(basepath, &baseend, false) != ROOT_VOLUME)
+ {
+ basepath_max = baseend - basepath;
+ /* strip leading separators from component */
+ while (*component == PATH_SEPCH)
+ component++;
+ } else {
+ /* component is absolute with no drive/volume, but basepath doesn't
+ * have a volume either... we must be on root volume */
+ basepath = component;
+ component = "";
+ basepath_max = -1u;
+ }
+ }
+ /* else component likely already has drive/volume name */
+ else
+ #endif
+ {
+ /* 'component' is absolute; replace all */
+ basepath = component;
+ component = "";
+ basepath_max = -1u;
+ }
}
/* if basepath is not null or empty, buffer contents are replaced,