diff --git a/core/entity/fs_file_info.go b/core/entity/fs_file_info.go index 68d0f0a6..0d58b7c9 100644 --- a/core/entity/fs_file_info.go +++ b/core/entity/fs_file_info.go @@ -6,56 +6,16 @@ import ( ) type FsFileInfo struct { - Name string `json:"name"` // file name - Path string `json:"path"` // file path - FullPath string `json:"full_path"` // file full path - 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 - 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 + Name string `json:"name"` // file name + Path string `json:"path"` // file path + FullPath string `json:"full_path"` // file full path + 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 + ModTime time.Time `json:"mod_time"` // modification time + Mode os.FileMode `json:"mode"` // file mode + Hash string `json:"hash"` // file hash } type FsFileInfoMap map[string]FsFileInfo diff --git a/core/fs/service.go b/core/fs/service.go index a6054bd6..7e883024 100644 --- a/core/fs/service.go +++ b/core/fs/service.go @@ -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) } } diff --git a/core/fs/service_test.go b/core/fs/service_test.go index 06f4624b..07d771c5 100644 --- a/core/fs/service_test.go +++ b/core/fs/service_test.go @@ -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) } }