mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-28 07:39:37 +08:00
- fix bare-metal Agent install config and executor path handling - support release package layout in deploy/install.sh and release workflow - add regression tests for Agent execution and deploy install script behavior
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
// DirEntry Agent 返回给 Master 的目录项。
|
|
type DirEntry struct {
|
|
Name string `json:"name"`
|
|
Path string `json:"path"`
|
|
IsDir bool `json:"isDir"`
|
|
Size int64 `json:"size"`
|
|
}
|
|
|
|
// listLocalDir 列出 Agent 所在机器的指定路径。
|
|
func listLocalDir(path string) ([]DirEntry, error) {
|
|
cleaned := filepath.Clean(strings.TrimSpace(path))
|
|
if strings.TrimSpace(path) == "" || cleaned == "." {
|
|
cleaned = "/"
|
|
}
|
|
entries, err := os.ReadDir(cleaned)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("read dir: %w", err)
|
|
}
|
|
result := make([]DirEntry, 0, len(entries))
|
|
for _, entry := range entries {
|
|
info, _ := entry.Info()
|
|
size := int64(0)
|
|
if info != nil && !entry.IsDir() {
|
|
size = info.Size()
|
|
}
|
|
result = append(result, DirEntry{
|
|
Name: entry.Name(),
|
|
Path: filepath.Join(cleaned, entry.Name()),
|
|
IsDir: entry.IsDir(),
|
|
Size: size,
|
|
})
|
|
}
|
|
sort.Slice(result, func(i, j int) bool {
|
|
if result[i].IsDir != result[j].IsDir {
|
|
return result[i].IsDir
|
|
}
|
|
return result[i].Name < result[j].Name
|
|
})
|
|
return result, nil
|
|
}
|