mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
fix: Update FsFileInfo to use pointer slices for children and remove redundant getter methods
This commit is contained in:
@@ -12,50 +12,10 @@ type FsFileInfo struct {
|
||||
Extension string `json:"extension"` // file extension
|
||||
IsDir bool `json:"is_dir"` // whether it is directory
|
||||
FileSize int64 `json:"file_size"` // file size (bytes)
|
||||
Children []FsFileInfo `json:"children"` // children for subdirectory
|
||||
Children []*FsFileInfo `json:"children"` // children for subdirectory
|
||||
ModTime time.Time `json:"mod_time"` // modification time
|
||||
Mode os.FileMode `json:"mode"` // file mode
|
||||
Hash string `json:"hash"` // file hash
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetName() string {
|
||||
return f.Name
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetPath() string {
|
||||
return f.Path
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetFullPath() string {
|
||||
return f.FullPath
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetExtension() string {
|
||||
return f.Extension
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetIsDir() bool {
|
||||
return f.IsDir
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetFileSize() int64 {
|
||||
return f.FileSize
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetModTime() time.Time {
|
||||
return f.ModTime
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetMode() os.FileMode {
|
||||
return f.Mode
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetHash() string {
|
||||
return f.Hash
|
||||
}
|
||||
|
||||
func (f *FsFileInfo) GetChildren() []FsFileInfo {
|
||||
return f.Children
|
||||
}
|
||||
|
||||
type FsFileInfoMap map[string]FsFileInfo
|
||||
|
||||
@@ -67,15 +67,15 @@ func (svc *Service) List(path string) (files []entity.FsFileInfo, err error) {
|
||||
}
|
||||
|
||||
if parentDir := filepath.Dir(p); parentDir != p && dirMap[parentDir] != nil {
|
||||
dirMap[parentDir].Children = append(dirMap[parentDir].Children, *fi)
|
||||
dirMap[parentDir].Children = append(dirMap[parentDir].Children, fi)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if rootInfo, ok := dirMap[fullPath]; ok {
|
||||
for _, info := range rootInfo.GetChildren() {
|
||||
files = append(files, info)
|
||||
for _, info := range rootInfo.Children {
|
||||
files = append(files, *info)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestService_List(t *testing.T) {
|
||||
// Use a map to verify presence and characteristics of files/directories to avoid order issues
|
||||
items := make(map[string]bool)
|
||||
for _, item := range files {
|
||||
items[item.GetName()] = item.GetIsDir()
|
||||
items[item.Name] = item.IsDir
|
||||
}
|
||||
|
||||
_, file1Exists := items["file1.txt"]
|
||||
@@ -55,8 +55,8 @@ func TestService_List(t *testing.T) {
|
||||
assert.True(t, subdirExists)
|
||||
assert.True(t, emptyExists) // Verify that the empty directory is included
|
||||
|
||||
if subdirExists && len(files[2].GetChildren()) > 0 {
|
||||
assert.Equal(t, "file3.txt", files[2].GetChildren()[0].GetName())
|
||||
if subdirExists && len(files[2].Children) > 0 {
|
||||
assert.Equal(t, "file3.txt", files[2].Children[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user