From 505ac6436d8a1b70eead14b0b36a5c1f0fbe71d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 27 Jun 2022 17:46:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E6=9D=83?= =?UTF-8?q?=E9=99=90=E4=BF=A1=E6=81=AF=E7=9A=84=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ls.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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", + }, + } +}