fix(files): separate the link flag from the entry type so a symlinked dir stays a dir
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-12 08:44:16
Commit25d165d9
Parentsb31e9c35
Changed files
src/plugin_files.c+4−10■■■■■
src/ui.html+1−1■■
src/ui_html.h+1−1■■
tests/run.sh+4−0■■■■
8 files+10−12
Diff
docs/ui-1024-dark.png+0−0■
index 57fe210..5a38f79 100644
binary image
Binary image file
docs/ui-1024-light.png+0−0■
index ba80b3e..6600e9f 100644
binary image
Binary image file
docs/ui-1440-dark.png+0−0■
index 3814d6b..e0a30a7 100644
binary image
Binary image file
docs/ui-1440-light.png+0−0■
index 3df2266..b1e53a4 100644
binary image
Binary image file
src/plugin_files.c+4−10■■■■■
index af2a48d..42123f4 100644
--- a/src/plugin_files.c
+++ b/src/plugin_files.c
@@ -752,13 +752,6 @@ static void do_roots(void)
752752 /* ?action=ls&path=<abs> */
753753 /* ------------------------------------------------------------------ */
754754
755-static const char *ent_kind(const ent_t *e)
756-{
757- if (e->is_dir) return "dir";
758- if (e->is_link) return "link";
759- return "file";
760-}
761-
762755 static void do_ls(const char *raw_path, const char *qs)
763756 {
764757 char canon[PATH_SZ];
@@ -817,9 +810,10 @@ static void do_ls(const char *raw_path, const char *qs)
817810 sprintf(mode, "%04o", ents[i].mode & 07777);
818811 buf_puts(&b, i ? ",\n {\"name\":" : "\n {\"name\":");
819812 json_str(&b, ents[i].name);
820- buf_puts(&b, ",\"type\":\"");
821- buf_puts(&b, ent_kind(&ents[i]));
822- buf_printf(&b, "\",\"size\":%lld,\"mtime\":\"%s\",\"mode\":\"%s\"}",
813+ buf_printf(&b, ",\"type\":\"%s\",\"link\":%s,\"size\":%lld,"
814+ "\"mtime\":\"%s\",\"mode\":\"%s\"}",
815+ ents[i].is_dir ? "dir" : "file",
816+ ents[i].is_link ? "true" : "false",
823817 ents[i].size, iso, mode);
824818 }
825819 buf_puts(&b, "\n]}\n");
src/ui.html+1−1■■
index 41c06e7..db15734 100644
--- a/src/ui.html
+++ b/src/ui.html
@@ -340,7 +340,7 @@ function renderEntries(){
340340 var b=document.createElement('button');
341341 b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');
342342 var ic=document.createElement('span');ic.className='ico';
343- ic.innerHTML = e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img : (e.type==='link'?SVG.link:SVG.file));
343+ ic.innerHTML = e.link?SVG.link : (e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img:SVG.file));
344344 var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;
345345 var mt=document.createElement('span');mt.className='mt';
346346 mt.textContent=(e.type==='dir'?'':fmtSize(e.size));
src/ui_html.h+1−1■■
index edb635e..8b1fd7d 100644
--- a/src/ui_html.h
+++ b/src/ui_html.h
@@ -345,7 +345,7 @@ static const char *UI_HTML =
345345 " var b=document.createElement('button');\n"
346346 " b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');\n"
347347 " var ic=document.createElement('span');ic.className='ico';\n"
348- " ic.innerHTML = e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img : (e.type==='link'?SVG.link:SVG.file));\n"
348+ " ic.innerHTML = e.link?SVG.link : (e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img:SVG.file));\n"
349349 " var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;\n"
350350 " var mt=document.createElement('span');mt.className='mt';\n"
351351 " mt.textContent=(e.type==='dir'?'':fmtSize(e.size));\n"
tests/run.sh+4−0■■■■
index d8a02de..bba5439 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -199,6 +199,10 @@ json_ok "empty dir answers count 0" "$R" "d['count']==0 and d['entries']==[]"
199199
200200 R=$(api "action=ls&path=$FX/goodlink")
201201 json_ok "symlink inside the root is browsable as a file" "$R" "'ok' in d"
202+R=$(api "action=ls&path=$FX")
203+json_ok "symlink entry is flagged link=true" "$R" "any(e['name']=='goodlink' and e['link'] is True for e in d['entries'])"
204+json_ok "plain file is link=false" "$R" "any(e['name']=='a.txt' and e['link'] is False for e in d['entries'])"
205+json_ok "every entry carries a link flag" "$R" "all('link' in e for e in d['entries'])"
202206
203207 R=$(api "action=ls")
204208 json_ok "ls without path defaults to the first root" "$R" "d['ok'] is True and d['path'].startswith('/')"
205209
docs/ui-1024-dark.png+0−0■
index 57fe210..5a38f79 100644index 57fe210..5a38f79 100644
binary image
Binary image file
docs/ui-1024-light.png+0−0■
index ba80b3e..6600e9f 100644index ba80b3e..6600e9f 100644
binary image
Binary image file
docs/ui-1440-dark.png+0−0■
index 3814d6b..e0a30a7 100644index 3814d6b..e0a30a7 100644
binary image
Binary image file
docs/ui-1440-light.png+0−0■
index 3df2266..b1e53a4 100644index 3df2266..b1e53a4 100644
binary image
Binary image file
src/plugin_files.c+4−10■■■■■
index af2a48d..42123f4 100644index af2a48d..42123f4 100644
--- a/src/plugin_files.c--- a/src/plugin_files.c
+++ b/src/plugin_files.c+++ b/src/plugin_files.c
@@ -752,13 +752,6 @@ static void do_roots(void)@@ -752,13 +752,6 @@ static void do_roots(void)
752 /* ?action=ls&path=<abs> */752 /* ?action=ls&path=<abs> */
753 /* ------------------------------------------------------------------ */753 /* ------------------------------------------------------------------ */
754 754
755-static const char *ent_kind(const ent_t *e)
756-{
757- if (e->is_dir) return "dir";
758- if (e->is_link) return "link";
759- return "file";
760-}
761-
762 static void do_ls(const char *raw_path, const char *qs)755 static void do_ls(const char *raw_path, const char *qs)
763 {756 {
764 char canon[PATH_SZ];757 char canon[PATH_SZ];
@@ -817,9 +810,10 @@ static void do_ls(const char *raw_path, const char *qs)@@ -817,9 +810,10 @@ static void do_ls(const char *raw_path, const char *qs)
817 sprintf(mode, "%04o", ents[i].mode & 07777);810 sprintf(mode, "%04o", ents[i].mode & 07777);
818 buf_puts(&b, i ? ",\n {\"name\":" : "\n {\"name\":");811 buf_puts(&b, i ? ",\n {\"name\":" : "\n {\"name\":");
819 json_str(&b, ents[i].name);812 json_str(&b, ents[i].name);
820- buf_puts(&b, ",\"type\":\"");813+ buf_printf(&b, ",\"type\":\"%s\",\"link\":%s,\"size\":%lld,"
821- buf_puts(&b, ent_kind(&ents[i]));814+ "\"mtime\":\"%s\",\"mode\":\"%s\"}",
822- buf_printf(&b, "\",\"size\":%lld,\"mtime\":\"%s\",\"mode\":\"%s\"}",815+ ents[i].is_dir ? "dir" : "file",
816+ ents[i].is_link ? "true" : "false",
823 ents[i].size, iso, mode);817 ents[i].size, iso, mode);
824 }818 }
825 buf_puts(&b, "\n]}\n");819 buf_puts(&b, "\n]}\n");
src/ui.html+1−1■■
index 41c06e7..db15734 100644index 41c06e7..db15734 100644
--- a/src/ui.html--- a/src/ui.html
+++ b/src/ui.html+++ b/src/ui.html
@@ -340,7 +340,7 @@ function renderEntries(){@@ -340,7 +340,7 @@ function renderEntries(){
340 var b=document.createElement('button');340 var b=document.createElement('button');
341 b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');341 b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');
342 var ic=document.createElement('span');ic.className='ico';342 var ic=document.createElement('span');ic.className='ico';
343- ic.innerHTML = e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img : (e.type==='link'?SVG.link:SVG.file));343+ ic.innerHTML = e.link?SVG.link : (e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img:SVG.file));
344 var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;344 var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;
345 var mt=document.createElement('span');mt.className='mt';345 var mt=document.createElement('span');mt.className='mt';
346 mt.textContent=(e.type==='dir'?'':fmtSize(e.size));346 mt.textContent=(e.type==='dir'?'':fmtSize(e.size));
src/ui_html.h+1−1■■
index edb635e..8b1fd7d 100644index edb635e..8b1fd7d 100644
--- a/src/ui_html.h--- a/src/ui_html.h
+++ b/src/ui_html.h+++ b/src/ui_html.h
@@ -345,7 +345,7 @@ static const char *UI_HTML =@@ -345,7 +345,7 @@ static const char *UI_HTML =
345 " var b=document.createElement('button');\n"345 " var b=document.createElement('button');\n"
346 " b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');\n"346 " b.className='row'+(e.type==='dir'?' dir':'')+(i===selIndex?' sel':'');\n"
347 " var ic=document.createElement('span');ic.className='ico';\n"347 " var ic=document.createElement('span');ic.className='ico';\n"
348- " ic.innerHTML = e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img : (e.type==='link'?SVG.link:SVG.file));\n"348+ " ic.innerHTML = e.link?SVG.link : (e.type==='dir'?SVG.dir : (isImage(e.name)?SVG.img:SVG.file));\n"
349 " var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;\n"349 " var nm=document.createElement('span');nm.className='nm';nm.textContent=e.name;\n"
350 " var mt=document.createElement('span');mt.className='mt';\n"350 " var mt=document.createElement('span');mt.className='mt';\n"
351 " mt.textContent=(e.type==='dir'?'':fmtSize(e.size));\n"351 " mt.textContent=(e.type==='dir'?'':fmtSize(e.size));\n"
tests/run.sh+4−0■■■■
index d8a02de..bba5439 100755index d8a02de..bba5439 100755
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -199,6 +199,10 @@ json_ok "empty dir answers count 0" "$R" "d['count']==0 and d['entries']==[]"@@ -199,6 +199,10 @@ json_ok "empty dir answers count 0" "$R" "d['count']==0 and d['entries']==[]"
199 199
200 R=$(api "action=ls&path=$FX/goodlink")200 R=$(api "action=ls&path=$FX/goodlink")
201 json_ok "symlink inside the root is browsable as a file" "$R" "'ok' in d"201 json_ok "symlink inside the root is browsable as a file" "$R" "'ok' in d"
202+R=$(api "action=ls&path=$FX")
203+json_ok "symlink entry is flagged link=true" "$R" "any(e['name']=='goodlink' and e['link'] is True for e in d['entries'])"
204+json_ok "plain file is link=false" "$R" "any(e['name']=='a.txt' and e['link'] is False for e in d['entries'])"
205+json_ok "every entry carries a link flag" "$R" "all('link' in e for e in d['entries'])"
202 206
203 R=$(api "action=ls")207 R=$(api "action=ls")
204 json_ok "ls without path defaults to the first root" "$R" "d['ok'] is True and d['path'].startswith('/')"208 json_ok "ls without path defaults to the first root" "$R" "d['ok'] is True and d['path'].startswith('/')"
205209