mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
fix: Remove getModTime() to use ModTime() from os.FileInfo directly (#39623)
- Use ModTime from os.FileInfo directly instead of custom getModTime implementation. - Removed test case for getModTime(). Signed-off-by: Gofastasf gofastasf@gmail.com Signed-off-by: Go gofastasf@gmail.com Signed-off-by: Gofastasf <gofastasf@gmail.com>
This commit is contained in:
parent
15c8798b93
commit
664a8a25f4
@ -23,7 +23,6 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"go.uber.org/zap"
|
||||
@ -155,11 +154,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
|
||||
}
|
||||
}
|
||||
@ -176,11 +171,14 @@ func (lcm *LocalChunkManager) WalkWithPrefix(ctx context.Context, prefix string,
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -263,19 +261,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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user