]> Sergey Matveev's repositories - godlighty.git/commitdiff
Show symbolic link values
authorSergey Matveev <stargrave@stargrave.org>
Tue, 15 Nov 2022 19:57:28 +0000 (22:57 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 15 Nov 2022 19:58:29 +0000 (22:58 +0300)
dirlist.go
dirlist.tmpl
godlighty.go
handler.go

index 82b360650175b46ee7a1f5cc9e5caedd649219c2..49976a3b83585df5e8078ef54373353adde52d20 100644 (file)
@@ -22,6 +22,7 @@ import (
        "html/template"
        "io/fs"
        "os"
+       "path"
        "sort"
        "time"
 
@@ -57,11 +58,12 @@ type DirListFile struct {
        IsDir   bool
        Type    string
        ModTime string
+       Symlink string
 }
 
 func dirList(
        cfg *HostCfg,
-       dir string,
+       dir, pth string,
        entries []os.DirEntry,
        readme string,
 ) (*os.File, error) {
@@ -83,6 +85,9 @@ func dirList(
                } else {
                        file.Type = mediaType(file.Name, cfg.MIMEs)
                }
+               if (entry.Type() & fs.ModeSymlink) > 0 {
+                       file.Symlink, _ = os.Readlink(path.Join(pth, fi.Name()))
+               }
                files = append(files, file)
        }
        fd, err := os.CreateTemp("", "godlist-dirlist-")
index 5034c5f6f1dc586b4c414be1351cc92f068ebf5e..8fb266fad4c545397a4e50b802bcf4a3184478cc 100644 (file)
 <table border=1>
 <tr><th>&nbsp;</th><th>Name</th><th>Mtime</th><th>Size</th><th>Type</th></tr>
 {{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}}<tr>
-  <td>{{.Idx}}</td>
+  <td {{if .Symlink}}rowspan="2"{{end}}>{{.Idx}}</td>
   <td><a href="{{$Root}}{{$Dir}}{{.Name}}{{if .IsDir}}/{{end -}}"><tt>
     {{- .Name}}{{if .IsDir}}/{{end}}</tt></a></td>
   <td><tt>{{.ModTime}}</tt></td>
   <td>{{.Size}}</td>
   <td><tt>{{if .IsDir}}dir{{else}}{{.Type}}{{end}}</tt></td>
-</tr>
+</tr>{{if .Symlink}}<tr><td colspan="4"><tt>-&gt; {{.Symlink}}</tt></td></tr>{{end}}
 {{end -}}
 </table>
 </body>
index 4a5c458a41c30f52dcaf1c3dfb7aad0abf809bc7..686ee990d53b29b851ac41d5fa1ffe026d14790e 100644 (file)
@@ -1,6 +1,6 @@
 // Highly-customizable HTTP, HTTP/2, HTTPS server
 package godlighty
 
-const Version = "godlighty/0.1.0"
+const Version = "godlighty/0.2.0"
 
 var BindAddr string
index d7037b43f109f008dfda8e1deddc0750f785cb7f..1fcbb7e821a33b5f3156feb8a8fbe011f2c29a9d 100644 (file)
@@ -205,7 +205,7 @@ IndexLookup:
                                        break
                                }
                        }
-                       fd, err = dirList(cfg, r.URL.Path, entries, string(readme))
+                       fd, err = dirList(cfg, r.URL.Path, pth, entries, string(readme))
                        if err != nil {
                                printErr(http.StatusInternalServerError, err)
                                http.Error(w, "internal error", http.StatusInternalServerError)