summaryrefslogtreecommitdiff
path: root/apps/filetree.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/filetree.c')
-rw-r--r--apps/filetree.c58
1 files changed, 42 insertions, 16 deletions
diff --git a/apps/filetree.c b/apps/filetree.c
index 4f59804686..66b5c843ca 100644
--- a/apps/filetree.c
+++ b/apps/filetree.c
@@ -477,41 +477,46 @@ static void ft_apply_skin_file(char *buf, char *file, const int maxlen)
477 477
478int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename) 478int ft_assemble_path(char *buf, size_t bufsz, const char* currdir, const char* filename)
479{ 479{
480 int len; 480 size_t len;
481 if (!filename) 481 if (!filename)
482 filename = ""; 482 filename = "";
483
483#ifdef HAVE_MULTIVOLUME 484#ifdef HAVE_MULTIVOLUME
484 if (currdir && currdir[0] && currdir[1]) /* Not in / */ 485 if (currdir && currdir[0] && currdir[1]) /* Not in / */
485 { 486 {
486 if (currdir[1] != VOL_START_TOK) 487 if (currdir[1] != VOL_START_TOK)
487 { 488 {
488 len = snprintf(buf, bufsz, "%s%s/%s", root_realpath(), currdir, filename); 489 len = path_append(buf, root_realpath(), currdir, bufsz);
490 if (len < bufsz)
491 len = path_append(buf, buf + len, filename, bufsz - len);
489 } 492 }
490 else 493 len = path_append(buf, currdir, filename, bufsz);
491 len = snprintf(buf, bufsz, "%s/%s", currdir, filename);
492 } 494 }
493 else /* In / */ 495 else /* In / */
494 { 496 {
495 if (filename[0] != VOL_START_TOK) 497 if (filename[0] != VOL_START_TOK)
496 { 498 {
497 len = snprintf(buf, bufsz, "%s/%s",root_realpath(), filename); 499 len = path_append(buf, root_realpath(), filename, bufsz);
498 } 500 }
499 else 501 else
500 len = snprintf(buf, bufsz, "/%s", filename); 502 len = path_append(buf, PATH_SEPSTR, filename, bufsz);
501 } 503 }
502#else 504#else
503 if (currdir && currdir[0] && currdir[1]) /* Not in / */ 505 if (currdir && currdir[0] && currdir[1]) /* Not in / */
504 { 506 {
505 len = snprintf(buf, bufsz, "%s%s/%s", root_realpath(), currdir, filename); 507 len = path_append(buf, root_realpath(), currdir, bufsz);
508 if(len < bufsz)
509 len = path_append(buf, buf + len, filename, bufsz - len);
506 } 510 }
507 else /* In / */ 511 else /* In / */
508 { 512 {
509 len = snprintf(buf, bufsz, "%s/%s",root_realpath(), filename); 513 len = path_append(buf, root_realpath(), filename, bufsz);
510 } 514 }
511#endif 515#endif
512 if ((unsigned) len > bufsz) 516
517 if (len > bufsz)
513 splash(HZ, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR)); 518 splash(HZ, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
514 return len; 519 return (int)len;
515} 520}
516 521
517int ft_enter(struct tree_context* c) 522int ft_enter(struct tree_context* c)
@@ -528,7 +533,6 @@ int ft_enter(struct tree_context* c)
528 533
529 int file_attr = file->attr; 534 int file_attr = file->attr;
530 ft_assemble_path(buf, sizeof(buf), c->currdir, file->name); 535 ft_assemble_path(buf, sizeof(buf), c->currdir, file->name);
531
532 if (file_attr & ATTR_DIRECTORY) { 536 if (file_attr & ATTR_DIRECTORY) {
533 memcpy(c->currdir, buf, sizeof(c->currdir)); 537 memcpy(c->currdir, buf, sizeof(c->currdir));
534 if ( c->dirlevel < MAX_DIR_LEVELS ) 538 if ( c->dirlevel < MAX_DIR_LEVELS )
@@ -814,17 +818,39 @@ int ft_exit(struct tree_context* c)
814 extern char lastfile[]; /* from tree.c */ 818 extern char lastfile[]; /* from tree.c */
815 char buf[MAX_PATH]; 819 char buf[MAX_PATH];
816 int rc = 0; 820 int rc = 0;
817 bool exit_func = false; 821 bool exit_func = false;
818
819 int i = strlen(c->currdir); 822 int i = strlen(c->currdir);
820 if (i>1) { 823 if (i>1) {
821 while (c->currdir[i-1]!='/') 824 while (c->currdir[i-1]!=PATH_SEPCH)
822 i--; 825 i--;
823 strcpy(buf,&c->currdir[i]); 826 strcpy(buf,&c->currdir[i]);
824 if (i==1) 827 if (i==1)
825 c->currdir[i]=0; 828 c->currdir[i]='\0';
826 else 829 else
827 c->currdir[i-1]=0; 830 c->currdir[i-1]='\0';
831
832#ifdef HAVE_MULTIVOLUME /* un-redirect the realpath */
833 if ((unsigned)c->dirlevel<=2) /* only expect redirect two levels max */
834 {
835 char *currdir = c->currdir;
836 const char *root = root_realpath();
837 int len = i-1;
838 /* compare to the root path bail if they don't match except single '/' */
839 for (; len > 0 && *root != '\0' && *root == *currdir; len--)
840 {
841 root++;
842 currdir++;
843 }
844 if (*root == PATH_SEPCH) /* root may have trailing slash */
845 root++;
846 if (*root == '\0' &&
847 (len == 0 || (len == 1 && *currdir == PATH_SEPCH)))
848 {
849 strcpy(c->currdir, PATH_ROOTSTR);
850 c->dirlevel=1;
851 }
852 }
853#endif
828 854
829 if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1) 855 if (*c->dirfilter > NUM_FILTER_MODES && c->dirlevel < 1)
830 exit_func = true; 856 exit_func = true;