diff --git a/ls.go b/ls.go index 72d2649..d6535c3 100644 --- a/ls.go +++ b/ls.go @@ -87,5 +87,35 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) { func (l *ls) parseFileInfo(fileLine string) *define.LsFileInfo { fileInfoArr := strings.Split(fileLine, " ") fmt.Println("文件信息 : ", fileInfoArr) + fmt.Println(l.getFilePermission(fileInfoArr[0])) return nil } + +// getFilePermission 解析文件权限信息 , 根据 drwxrwxrwx 这个规范解析 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:37 2022/6/27 +func (l *ls) getFilePermission(permissionLayout string) (bool, bool, *define.FullPermission) { + permissionArr := strings.Split(permissionLayout, "") + if len(permissionArr) < 10 { + return false, false, nil + } + return permissionArr[0] == "l", permissionArr[0] == "d", &define.FullPermission{ + User: define.FilePermission{ + Read: permissionArr[1] == "r", + Write: permissionArr[2] == "w", + Exec: permissionArr[3] == "x", + }, + Group: define.FilePermission{ + Read: permissionArr[4] == "r", + Write: permissionArr[5] == "w", + Exec: permissionArr[6] == "x", + }, + Other: define.FilePermission{ + Read: permissionArr[7] == "r", + Write: permissionArr[8] == "w", + Exec: permissionArr[9] == "x", + }, + } +}