文件列表,填充路径信息
This commit is contained in:
parent
98203938f4
commit
803e3fc0ab
21
ls.go
21
ls.go
@ -8,6 +8,7 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
@ -24,6 +25,7 @@ func NewLs(workDir string) *ls {
|
||||
return &ls{
|
||||
workDir: workDir,
|
||||
paramList: []string{"-l"},
|
||||
relativeDir: "." + string(filepath.Separator),
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,6 +33,7 @@ type ls struct {
|
||||
workDir string
|
||||
paramList []string
|
||||
isRecursive bool // 是否递归查询
|
||||
relativeDir string // 相对目录
|
||||
}
|
||||
|
||||
// ShowHideFile 显示隐藏文件
|
||||
@ -77,7 +80,10 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) {
|
||||
continue
|
||||
}
|
||||
if len(itemArr) < 9 {
|
||||
// 设置目录 TODO
|
||||
// 设置目录
|
||||
if strings.HasPrefix(item, "."+string(filepath.Separator)) && strings.HasSuffix(item, ":") {
|
||||
l.relativeDir = strings.TrimRight(item, ":")
|
||||
}
|
||||
continue
|
||||
}
|
||||
fileListResult = append(fileListResult, l.parseFileInfo(item))
|
||||
@ -99,6 +105,7 @@ func (l *ls) parseFileInfo(fileLine string) define.LsFileInfo {
|
||||
}
|
||||
}
|
||||
fileInfo := define.LsFileInfo{}
|
||||
fileInfo.IsLink, fileInfo.IsDir, fileInfo.Permission = l.getFilePermission(fileInfoArr[0])
|
||||
// 是否链接 / 是否目录 / 文件权限解析
|
||||
fileInfo.Name = fileInfoArr[8]
|
||||
fileInfo.User = fileInfoArr[2]
|
||||
@ -106,16 +113,22 @@ func (l *ls) parseFileInfo(fileLine string) define.LsFileInfo {
|
||||
fileInfo.ModifyTime = strings.Join(fileInfoArr[5:8], " ")
|
||||
_ = util.ConvertAssign(&fileInfo.Size, fileInfoArr[4])
|
||||
_ = util.ConvertAssign(&fileInfo.ReferenceCnt, fileInfoArr[1])
|
||||
if fileInfo.IsDir {
|
||||
fileInfo.Type = "-"
|
||||
} else {
|
||||
nameArr := strings.Split(fileInfo.Name, ".")
|
||||
if len(nameArr) < 2 {
|
||||
fileInfo.Type = "unknown"
|
||||
} else {
|
||||
fileInfo.Type = nameArr[len(nameArr)-1]
|
||||
}
|
||||
fileInfo.IsLink, fileInfo.IsDir, fileInfo.Permission = l.getFilePermission(fileInfoArr[0])
|
||||
if fileInfo.IsLink {
|
||||
fileInfo.SourcePath = fileInfoArr[0]
|
||||
}
|
||||
|
||||
if fileInfo.IsLink {
|
||||
fileInfo.SourcePath = fileInfoArr[10]
|
||||
}
|
||||
fileInfo.RelativePath = l.relativeDir
|
||||
fileInfo.FullPath = strings.ReplaceAll(l.workDir+string(filepath.Separator)+l.relativeDir, string(filepath.Separator)+"."+string(filepath.Separator), string(filepath.Separator))
|
||||
return fileInfo
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user