增加权限信息解析

This commit is contained in:
白茶清欢 2022-06-27 18:07:40 +08:00
parent 505ac6436d
commit 8c3a8c5da2

15
ls.go
View File

@ -8,7 +8,6 @@
package command package command
import ( import (
"fmt"
"strings" "strings"
"git.zhangdeman.cn/zhangdeman/command/define" "git.zhangdeman.cn/zhangdeman/command/define"
@ -64,6 +63,7 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) {
} }
resultStr := string(result.Output) resultStr := string(result.Output)
fileList := strings.Split(resultStr, "\n") fileList := strings.Split(resultStr, "\n")
fileListResult := make([]define.LsFileInfo, 0)
for _, item := range fileList { for _, item := range fileList {
if item == "." || item == ".." || len(item) == 0 { if item == "." || item == ".." || len(item) == 0 {
// 忽略 . 和 .. // 忽略 . 和 ..
@ -74,9 +74,9 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) {
// 过滤掉对于文件总数的输出 // 过滤掉对于文件总数的输出
continue continue
} }
l.parseFileInfo(item) fileListResult = append(fileListResult, l.parseFileInfo(item))
} }
return result, nil return result, fileListResult
} }
// parseFileInfo 解析文件信息 // parseFileInfo 解析文件信息
@ -84,11 +84,12 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) {
// Author : go_developer@163.com<白茶清欢> // Author : go_developer@163.com<白茶清欢>
// //
// Date : 17:35 2022/6/27 // Date : 17:35 2022/6/27
func (l *ls) parseFileInfo(fileLine string) *define.LsFileInfo { func (l *ls) parseFileInfo(fileLine string) define.LsFileInfo {
fileInfoArr := strings.Split(fileLine, " ") fileInfoArr := strings.Split(fileLine, " ")
fmt.Println("文件信息 : ", fileInfoArr) fileInfo := define.LsFileInfo{}
fmt.Println(l.getFilePermission(fileInfoArr[0])) // 是否链接 / 是否目录 / 文件权限解析
return nil fileInfo.IsLink, fileInfo.IsDir, fileInfo.Permission = l.getFilePermission(fileInfoArr[0])
return fileInfo
} }
// getFilePermission 解析文件权限信息 , 根据 drwxrwxrwx 这个规范解析 // getFilePermission 解析文件权限信息 , 根据 drwxrwxrwx 这个规范解析