From 07f3ee38e50ba6cef7a515b3fad1a37921fa1160 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sun, 6 Jan 2019 12:59:53 +0000 Subject: [PATCH] fix: dont fail when can't detect file type (#609) License: MIT Signed-off-by: Henrique Dias --- files/file.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/files/file.go b/files/file.go index 3dbb092a..f7253a1e 100644 --- a/files/file.go +++ b/files/file.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "hash" "io" + "log" "mime" "net/http" "os" @@ -127,16 +128,24 @@ func (i *FileInfo) Checksum(algo string) error { } func (i *FileInfo) detectType(modify, saveContent bool) error { + // failing to detect the type should not return error. + // imagine the situation where a file in a dir with thousands + // of files couldn't be opened: we'd have immediately + // a 500 even though it doesn't matter. So we just log it. reader, err := i.Fs.Open(i.Path) if err != nil { - return err + log.Print(err) + i.Type = "blob" + return nil } defer reader.Close() buffer := make([]byte, 512) n, err := reader.Read(buffer) if err != nil && err != io.EOF { - return err + log.Print(err) + i.Type = "blob" + return nil } mimetype := mime.TypeByExtension(i.Extension)