From: Urban Wallasch Date: Fri, 5 Apr 2019 17:38:28 +0000 (+0200) Subject: * Include file modification time in directory listings. X-Git-Tag: v0.2~6 X-Git-Url: https://git.packet-gain.de/?a=commitdiff_plain;h=65c59e2f17812ec38f1c5a91dc091d60cb75cefd;p=gogopherd.git * Include file modification time in directory listings. --- diff --git a/gogopherd.go b/gogopherd.go index 4155a53..2b18b5b 100644 --- a/gogopherd.go +++ b/gogopherd.go @@ -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 e790c0c..1f229aa 100644 --- 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 */