From 916f3d789b6afaf7bfe161aeec391c8a35e354a8 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Fri, 28 Oct 2016 14:50:46 -0700 Subject: [PATCH] Size() returns 0 if file doesn't exist --- autofile.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/autofile.go b/autofile.go index ed9d549bf..36de9984a 100644 --- a/autofile.go +++ b/autofile.go @@ -107,6 +107,16 @@ func (af *AutoFile) openFile() error { func (af *AutoFile) Size() (int64, error) { af.mtx.Lock() defer af.mtx.Unlock() + if af.file == nil { + err := af.openFile() + if err != nil { + if err == os.ErrNotExist { + return 0, nil + } else { + return -1, err + } + } + } stat, err := af.file.Stat() if err != nil { return -1, err