From de4a08f3190eb3eb912e6d1dfbd46afe59d62555 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Sat, 8 Jun 2024 01:05:58 -0400 Subject: [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 --- apps/filetree.c | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 file 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) settings_apply_skins(); } +static const char *strip_slash(const char *path, const char *def) +{ + if (path) + { + while (*path == PATH_SEPCH) + path++; /* we don't want this treated as an absolute path */ + return path; + } + return def; +} + int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename) { size_t len; - if (!filename) - filename = ""; + const char *cd = strip_slash(currdir, ""); + filename = strip_slash(filename, ""); + /* remove slashes and NULL strings to make logic below simpler */ #ifdef HAVE_MULTIVOLUME - if (currdir && currdir[0] && currdir[1]) /* Not in / */ + /* Multi-volume device drives might be enumerated in root so everything + should be an absolute qualified path with / prepended */ + if (*cd != '\0') /* Not in / */ { - if (currdir[1] != VOL_START_TOK) + if (*cd == VOL_START_TOK) { - len = path_append(buf, root_realpath(), currdir, bufsz); - if (len < bufsz) - len = path_append(buf + len, PA_SEP_HARD, filename, bufsz - len); - } - len = path_append(buf, currdir, filename, bufsz); + /* use currdir, here we want the slash as it already contains the */ + len = path_append(buf, currdir, filename, bufsz); + } /* buf => /currdir/filename */ + else + { + len = path_append(buf, root_realpath(), cd, bufsz); /* //currdir */ + if(len < bufsz) + len += path_append(buf + len, PA_SEP_HARD, filename, bufsz - len); + } /* buf => //currdir/filename */ } else /* In / */ { - if (filename[0] != VOL_START_TOK) + if (*filename == VOL_START_TOK) { - len = path_append(buf, root_realpath(), filename, bufsz); - } - else len = path_append(buf, PATH_SEPSTR, filename, bufsz); + } /* buf => /filename */ + else + { + len = path_append(buf, root_realpath(), filename, bufsz); + } /* buf => //filename */ } #else - if (currdir && currdir[0] && currdir[1]) /* Not in / */ + /* Other devices might need a specific drive/dir prepended but its usually '/' */ + if (*cd != '\0') /* Not in / */ { - len = path_append(buf, root_realpath(), currdir, bufsz); + len = path_append(buf, root_realpath(), cd, bufsz);/* /currdir */ if(len < bufsz) - len = path_append(buf + len, PA_SEP_HARD, filename, bufsz - len); - } + len += path_append(buf + len, PA_SEP_HARD, filename, bufsz - len); + } /* buf => /currdir/filename */ else /* In / */ { len = path_append(buf, root_realpath(), filename, bufsz); - } + } /* buf => /filename */ #endif if (len > bufsz) -- cgit v1.2.3