From: Sergey Matveev Date: Tue, 15 Nov 2022 19:57:28 +0000 (+0300) Subject: Show symbolic link values X-Git-Url: http://www.git.stargrave.org/?p=godlighty.git;a=commitdiff_plain;h=0b1221d2cfb6c7a77aa428e77fd586229dbc5fb7 Show symbolic link values --- diff --git a/dirlist.go b/dirlist.go index 82b3606..49976a3 100644 --- a/dirlist.go +++ b/dirlist.go @@ -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-") diff --git a/dirlist.tmpl b/dirlist.tmpl index 5034c5f..8fb266f 100644 --- a/dirlist.tmpl +++ b/dirlist.tmpl @@ -12,13 +12,13 @@ {{$Dir := .Dir}}{{$Root := .Root}}{{range .Files}} - + - +{{if .Symlink}}{{end}} {{end -}}
 NameMtimeSizeType
{{.Idx}}{{.Idx}} {{- .Name}}{{if .IsDir}}/{{end}} {{.ModTime}} {{.Size}} {{if .IsDir}}dir{{else}}{{.Type}}{{end}}
-> {{.Symlink}}
diff --git a/godlighty.go b/godlighty.go index 4a5c458..686ee99 100644 --- a/godlighty.go +++ b/godlighty.go @@ -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 diff --git a/handler.go b/handler.go index d7037b4..1fcbb7e 100644 --- a/handler.go +++ b/handler.go @@ -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)