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
This commit is contained in:
paul cannon 2023-02-14 18:05:32 -06:00
parent 8c7e031ee3
commit 0e1c99f75a

View File

@ -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) { func (dir *Dir) EmptyTrash(ctx context.Context, namespace []byte, trashedBefore time.Time) (bytesEmptied int64, deletedKeys [][]byte, err error) {
defer mon.Task()(&ctx)(&err) defer mon.Task()(&ctx)(&err)
var errorsEncountered errs.Group var errorsEncountered errs.Group
err = dir.walkNamespaceInPath(ctx, namespace, dir.trashdir(), func(blobInfo storage.BlobInfo) error { err = dir.walkNamespaceInPath(ctx, namespace, dir.trashdir(), func(info storage.BlobInfo) error {
fileInfo, err := blobInfo.Stat(ctx) fileInfo, err := info.Stat(ctx)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil return nil
} }
if !errors.Is(err, ErrIsDir) { if errors.Is(err, ErrIsDir) {
errorsEncountered.Add(Error.New("%s: %s", fileInfo.Name(), err)) 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 return nil
} }
mtime := fileInfo.ModTime() mtime := fileInfo.ModTime()
if mtime.Before(trashedBefore) { 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 { if err != nil {
errorsEncountered.Add(err) errorsEncountered.Add(err)
return nil return nil
} }
deletedKeys = append(deletedKeys, blobInfo.BlobRef().Key) deletedKeys = append(deletedKeys, info.BlobRef().Key)
bytesEmptied += fileInfo.Size() bytesEmptied += fileInfo.Size()
} }
return nil return nil