]> Sergey Matveev's repositories - godlighty.git/blobdiff - dirlist.go
.xht
[godlighty.git] / dirlist.go
index 82b360650175b46ee7a1f5cc9e5caedd649219c2..ab631bb9a7d5b919b7f553678f1744929327ff0d 100644 (file)
@@ -1,6 +1,6 @@
 /*
 godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server
-Copyright (C) 2021-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -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-")