From 0f746b11d23ccd0af99cecbd5b41f0a8402b2bf3 Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Sat, 6 Apr 2019 13:33:18 +0200 Subject: [PATCH] * Evaluate errors returned by guessFiletype(). --- gogopherd.go | 10 ++++++++-- util.go | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gogopherd.go b/gogopherd.go index 5697fbd..1e6bfe7 100644 --- a/gogopherd.go +++ b/gogopherd.go @@ -47,7 +47,10 @@ func createIndex(selector string) (string, error) { 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()) + ftype, err := guessFiletype(dirname + pathSep + fi.Name()) + if check(err, "guessFiletype "+dirname+pathSep+fi.Name()) != nil { + continue + } list += ftype + fi.Name() + " | " + humanSize(fi.Size()) + " | " + fts + "\t" + selector + pathSep + fi.Name() + loc } else if cfg.fsymln && fmode&os.ModeSymlink != 0 { // create a reference with attributes matching the link target @@ -66,7 +69,10 @@ func createIndex(selector string) (string, error) { 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()) + ftype, err := guessFiletype(dirname + pathSep + fi.Name()) + if check(err, "guessFiletype "+dirname+pathSep+fi.Name()) != nil { + continue + } list += ftype + fi.Name() + " | " + humanSize(lfi.Size()) + " | " + fts + "\t" + selector + pathSep + fi.Name() + loc } } diff --git a/util.go b/util.go index 1f229aa..29d453b 100644 --- a/util.go +++ b/util.go @@ -90,7 +90,6 @@ func guessFiletype(path string) (string, error) { } buffer = buffer[:n] contentType := http.DetectContentType(buffer) - //tracer.Print("Content Type " + path + " == "+ contentType) shortType := strings.Split(contentType, ";")[0] genType := strings.Split(shortType, "/")[0] gopherType := "9" -- 2.30.2