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