From 0e1c99f75af84a3bc38e81c19ec877b50733cb57 Mon Sep 17 00:00:00 2001 From: paul cannon Date: Tue, 14 Feb 2023 18:05:32 -0600 Subject: [PATCH] storage/filestore: fix panic on fs error in EmptyTrash fileInfo is, of course, nil here, so we can't use fileInfo.Name() to report the location of the problem. Change-Id: Ia858a3795b127da0fc812d0a158b36ad344ff76b --- storage/filestore/dir.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/storage/filestore/dir.go b/storage/filestore/dir.go index 2ba6b3978..2c1ed7cdb 100644 --- a/storage/filestore/dir.go +++ b/storage/filestore/dir.go @@ -476,26 +476,33 @@ func (dir *Dir) RestoreTrash(ctx context.Context, namespace []byte) (keysRestore func (dir *Dir) EmptyTrash(ctx context.Context, namespace []byte, trashedBefore time.Time) (bytesEmptied int64, deletedKeys [][]byte, err error) { defer mon.Task()(&ctx)(&err) var errorsEncountered errs.Group - err = dir.walkNamespaceInPath(ctx, namespace, dir.trashdir(), func(blobInfo storage.BlobInfo) error { - fileInfo, err := blobInfo.Stat(ctx) + err = dir.walkNamespaceInPath(ctx, namespace, dir.trashdir(), func(info storage.BlobInfo) error { + fileInfo, err := info.Stat(ctx) if err != nil { if os.IsNotExist(err) { return nil } - if !errors.Is(err, ErrIsDir) { - errorsEncountered.Add(Error.New("%s: %s", fileInfo.Name(), err)) + if errors.Is(err, ErrIsDir) { + return nil + } + // it would be best if we could report the actual problematic path + if thisBlobInfo, ok := info.(*blobInfo); ok { + errorsEncountered.Add(Error.New("%s: %s", thisBlobInfo.path, err)) + } else { + // this is probably a v0PieceAccess; do what we can + errorsEncountered.Add(Error.New("blobRef %+v: %s", info.BlobRef(), err)) } return nil } mtime := fileInfo.ModTime() if mtime.Before(trashedBefore) { - err = dir.deleteWithStorageFormatInPath(ctx, dir.trashdir(), blobInfo.BlobRef(), blobInfo.StorageFormatVersion()) + err = dir.deleteWithStorageFormatInPath(ctx, dir.trashdir(), info.BlobRef(), info.StorageFormatVersion()) if err != nil { errorsEncountered.Add(err) return nil } - deletedKeys = append(deletedKeys, blobInfo.BlobRef().Key) + deletedKeys = append(deletedKeys, info.BlobRef().Key) bytesEmptied += fileInfo.Size() } return nil