From ed9816fd3088b56fa30216725cd4cbd62fb39bb5 Mon Sep 17 00:00:00 2001 From: Ivan Fraixedes Date: Fri, 19 Jun 2020 13:30:34 +0200 Subject: [PATCH] storage/filestore: Ignore IsNotExist error walking files A file piece could be deleted in between walking the list of files read from a directory and before we actually perform any operation on such file. When that happens, we don't want to return an error, we want to just ignore it and carry on. Change-Id: I8f6986070e5883599a08fccf8b125c075b30fe1b --- storage/filestore/dir.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/storage/filestore/dir.go b/storage/filestore/dir.go index 0cb005243..469e31a6e 100644 --- a/storage/filestore/dir.go +++ b/storage/filestore/dir.go @@ -701,12 +701,17 @@ func walkNamespaceWithPrefix(ctx context.Context, log *zap.Logger, namespace []b for _, name := range names { info, err := os.Lstat(keyDir + "/" + name) if err != nil { - if pErr, ok := err.(*os.PathError); ok { - if pErr.Err.Error() == "lstat" { - log.Error("Unable to read the disk, please verify the disk is not corrupt") - } + if os.IsNotExist(err) { + continue } - return err + + // convert to lowercase the perr.Op because Go reports inconsistently + // "lstat" in Linux and "Lstat" in Windows + if perr, ok := err.(*os.PathError); ok && strings.ToLower(perr.Op) == "lstat" { + log.Error("Unable to read the disk, please verify the disk is not corrupt") + } + + return errs.Wrap(err) } if info.Mode().IsDir() { continue