summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-06-08 01:05:58 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2024-06-14 01:40:19 -0400
commitde4a08f3190eb3eb912e6d1dfbd46afe59d62555 (patch)
treeab481ad305f8f8fb9c9951c582dd918ba5724926
parent935fb736e8ebc14e9c1358702c5562ee3b0f6c08 (diff)
downloadrockbox-de4a08f3190eb3eb912e6d1dfbd46afe59d62555.tar.gz
rockbox-de4a08f3190eb3eb912e6d1dfbd46afe59d62555.zip
[Bugfix] filetree.c ft_assemble_path() absolute currdir
path_append throws away the basepath if currdir starts with a slash I thought I had this fixed but it was just getting covered up instead step past all the slashes and use that for our append dir Change-Id: I170a2af99455cea09e6e695dfb89fdd42733bd4b
-rw-r--r--apps/filetree.c57
1 files changed, 39 insertions, 18 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 9550adbac2..eadb19ea59 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -473,43 +473,64 @@ static void ft_apply_skin_file(char *buf, char *file, const int maxlen)
473 settings_apply_skins(); 473 settings_apply_skins();
474} 474}
475 475
476static const char *strip_slash(const char *path, const char *def)
477{
478 if (path)
479 {
480 while (*path == PATH_SEPCH)
481 path++; /* we don't want this treated as an absolute path */
482 return path;
483 }
484 return def;
485}
486
476int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename) 487int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename)
477{ 488{
478 size_t len; 489 size_t len;
479 if (!filename) 490 const char *cd = strip_slash(currdir, "");
480 filename = ""; 491 filename = strip_slash(filename, "");
492 /* remove slashes and NULL strings to make logic below simpler */
481 493
482#ifdef HAVE_MULTIVOLUME 494#ifdef HAVE_MULTIVOLUME
483 if (currdir && currdir[0] && currdir[1]) /* Not in / */ 495 /* Multi-volume device drives might be enumerated in root so everything
496 should be an absolute qualified path with <drive>/ prepended */
497 if (*cd != '\0') /* Not in / */
484 { 498 {
485 if (currdir[1] != VOL_START_TOK) 499 if (*cd == VOL_START_TOK)
486 { 500 {
487 len = path_append(buf, root_realpath(), currdir, bufsz); 501 /* use currdir, here we want the slash as it already contains the <drive> */
488 if (len < bufsz) 502 len = path_append(buf, currdir, filename, bufsz);
489 len = path_append(buf + len, PA_SEP_HARD, filename, bufsz - len); 503 } /* buf => /currdir/filename */
490 } 504 else
491 len = path_append(buf, currdir, filename, bufsz); 505 {
506 len = path_append(buf, root_realpath(), cd, bufsz); /* /<drive>/currdir */
507 if(len < bufsz)
508 len += path_append(buf + len, PA_SEP_HARD, filename, bufsz - len);
509 } /* buf => /<drive>/currdir/filename */
492 } 510 }
493 else /* In / */ 511 else /* In / */
494 { 512 {
495 if (filename[0] != VOL_START_TOK) 513 if (*filename == VOL_START_TOK)
496 { 514 {
497 len = path_append(buf, root_realpath(), filename, bufsz);
498 }
499 else
500 len = path_append(buf, PATH_SEPSTR, filename, bufsz); 515 len = path_append(buf, PATH_SEPSTR, filename, bufsz);
516 } /* buf => /filename */
517 else
518 {
519 len = path_append(buf, root_realpath(), filename, bufsz);
520 } /* buf => /<drive>/filename */
501 } 521 }
502#else 522#else
503 if (currdir && currdir[0] && currdir[1]) /* Not in / */ 523 /* Other devices might need a specific drive/dir prepended but its usually '/' */
524 if (*cd != '\0') /* Not in / */
504 { 525 {
505 len = path_append(buf, root_realpath(), currdir, bufsz); 526 len = path_append(buf, root_realpath(), cd, bufsz);/* /currdir */
506 if(len < bufsz) 527 if(len < bufsz)
507 len = path_append(buf + len, PA_SEP_HARD, filename, bufsz - len); 528 len += path_append(buf + len, PA_SEP_HARD, filename, bufsz - len);
508 } 529 } /* buf => /currdir/filename */
509 else /* In / */ 530 else /* In / */
510 { 531 {
511 len = path_append(buf, root_realpath(), filename, bufsz); 532 len = path_append(buf, root_realpath(), filename, bufsz);
512 } 533 } /* buf => /filename */
513#endif 534#endif
514 535
515 if (len > bufsz) 536 if (len > bufsz)