* Include file modification time in directory listings.
authorUrban Wallasch <urban.wallasch@freenet.de>
Fri, 5 Apr 2019 17:38:28 +0000 (19:38 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Fri, 5 Apr 2019 17:38:28 +0000 (19:38 +0200)
gogopherd.go
util.go

index 4155a531662a49c001a3f025f67294d65da2b2cc..2b18b5bb30d22814762d2a68174af3541ada5d0a 100644 (file)
@@ -43,15 +43,16 @@ func createIndex(selector string) (string, error) {
                        continue
                }
                fmode := fi.Mode()
+               fts := humanDate(fi.ModTime())
                if fmode.IsDir() {
                        // create a directory reference
-                       list += "1" + fi.Name() + "\t" + selector + pathSep + fi.Name() + loc
+                       list += "1" + fi.Name() + " | DIR | " + fts + "\t" + selector + pathSep + fi.Name() + loc
                } else if fmode.IsRegular() {
                        // create a file reference
                        ftype, _ := guessFiletype(dirname + pathSep + fi.Name())
-                       list += ftype + fi.Name() + " (" + humanSize(fi.Size()) + ")\t" + selector + pathSep + fi.Name() + loc
+                       list += ftype + fi.Name() + " | " + humanSize(fi.Size()) + " | " + fts + "\t" + selector + pathSep + fi.Name() + loc
                } else if cfg.fsymln == true && fmode&os.ModeSymlink != 0 {
-                       // create a reference with a type matching the link target
+                       // create a reference with attributes matching the link target
                        linktarget, _ := os.Readlink(dirname + pathSep + fi.Name())
                        if linktarget[:1] != pathSep {
                                linktarget = dirname + pathSep + linktarget
@@ -60,13 +61,15 @@ func createIndex(selector string) (string, error) {
                        if check(err, "canonicalizePath "+path) == nil {
                                lfi, err := os.Stat(path)
                                if check(err, "Stat "+path) == nil {
-                                       if lfi.IsDir() {
+                                       fmode := fi.Mode()
+                                       fts := "[" + humanDate(lfi.ModTime()) + "]"
+                                       if fmode.IsDir() {
                                                // link points to a directory
-                                               list += "1" + fi.Name() + "\t" + selector + pathSep + fi.Name() + loc
-                                       } else if lfi.Mode().IsRegular() {
+                                               list += "1" + fi.Name() + " | DIR | " + fts + "\t" + selector + pathSep + fi.Name() + loc
+                                       } else if fmode.IsRegular() {
                                                // link points to a regular file
                                                ftype, _ := guessFiletype(dirname + pathSep + fi.Name())
-                                               list += ftype + fi.Name() + " (" + humanSize(lfi.Size()) + ")\t" + selector + pathSep + fi.Name() + loc
+                                               list += ftype + fi.Name() + " | " + humanSize(lfi.Size()) + " | " + fts + "\t" + selector + pathSep + fi.Name() + loc
                                        }
                                }
                        }
diff --git a/util.go b/util.go
index e790c0cf81c042baae2c00bf861b24677b8c8298..1f229aa79a585386a8987a60955d3191a26831f4 100644 (file)
--- a/util.go
+++ b/util.go
@@ -18,6 +18,7 @@ import (
        "os"
        "path/filepath"
        "strings"
+       "time"
 )
 
 var (
@@ -121,4 +122,8 @@ func humanSize(bytes int64) string {
        return fmt.Sprintf("%.*f %s", decimals, n, units[ui])
 }
 
+func humanDate(t time.Time) string {
+       return t.Format("2006-01-02 15:04:05 -07:00")
+}
+
 /* EOF */