diff --git a/internal/storage/local_chunk_manager.go b/internal/storage/local_chunk_manager.go index 1730c5cb79bfe..e9a8ba82cb563 100644 --- a/internal/storage/local_chunk_manager.go +++ b/internal/storage/local_chunk_manager.go @@ -155,11 +155,7 @@ func (lcm *LocalChunkManager) WalkWithPrefix(ctx context.Context, prefix string, } if strings.HasPrefix(filePath, prefix) && !f.IsDir() { - modTime, err := lcm.getModTime(filePath) - if err != nil { - return err - } - if !walkFunc(&ChunkObjectInfo{FilePath: filePath, ModifyTime: modTime}) { + if !walkFunc(&ChunkObjectInfo{FilePath: filePath, ModifyTime: f.ModTime()}) { return nil } } @@ -175,12 +171,15 @@ func (lcm *LocalChunkManager) WalkWithPrefix(ctx context.Context, prefix string, if ctx.Err() != nil { return ctx.Err() } - - modTime, err := lcm.getModTime(filePath) + + f, err := os.Stat(filePath) if err != nil { - return err + if errors.Is(err, os.ErrNotExist) { + return merr.WrapErrIoKeyNotFound(filePath) + } + return merr.WrapErrIoFailed(filePath, err) } - if !walkFunc(&ChunkObjectInfo{FilePath: filePath, ModifyTime: modTime}) { + if !walkFunc(&ChunkObjectInfo{FilePath: filePath, ModifyTime: f.ModTime()}) { return nil } } @@ -264,18 +263,3 @@ func (lcm *LocalChunkManager) RemoveWithPrefix(ctx context.Context, prefix strin return removeErr } -func (lcm *LocalChunkManager) getModTime(filepath string) (time.Time, error) { - fi, err := os.Stat(filepath) - if err != nil { - log.Warn("stat fileinfo error", - zap.String("filepath", filepath), - zap.Error(err), - ) - if os.IsNotExist(err) { - return time.Time{}, merr.WrapErrIoKeyNotFound(filepath) - } - return time.Time{}, merr.WrapErrIoFailed(filepath, err) - } - - return fi.ModTime(), nil -} diff --git a/internal/storage/local_chunk_manager_test.go b/internal/storage/local_chunk_manager_test.go index e9f41504b0c63..0420f98ce6b00 100644 --- a/internal/storage/local_chunk_manager_test.go +++ b/internal/storage/local_chunk_manager_test.go @@ -386,9 +386,6 @@ func TestLocalCM(t *testing.T) { assert.Nil(t, reader) assert.Error(t, err) - _, err = testCM.getModTime(key) - assert.Error(t, err) - err = testCM.Write(ctx, key, value) assert.NoError(t, err)