Skip to content

Commit

Permalink
fix: Remove getModTime() to use ModTime()
Browse files Browse the repository at this point in the history
- Use ModTime from os.FileInfo directly instead of custom getModTime implementation.
- Removed test case for getModTime().

Signed-off-by: Go [email protected]
  • Loading branch information
Gofastasf committed Jan 31, 2025
1 parent b3791a6 commit be0b77b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
32 changes: 8 additions & 24 deletions internal/storage/local_chunk_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
3 changes: 0 additions & 3 deletions internal/storage/local_chunk_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit be0b77b

Please sign in to comment.