From 8c3a8c5da2f3979d8c7b2c85879613c119187c64 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 18:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ls.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ls.go b/ls.go index d6535c3..cf9c0a4 100644 --- a/ls.go +++ b/ls.go @@ -8,7 +8,6 @@ package command import ( - "fmt" "strings" "git.zhangdeman.cn/zhangdeman/command/define" @@ -64,6 +63,7 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) { } resultStr := string(result.Output) fileList := strings.Split(resultStr, "\n") + fileListResult := make([]define.LsFileInfo, 0) for _, item := range fileList { if item == "." || item == ".." || len(item) == 0 { // 忽略 . 和 .. @@ -74,9 +74,9 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) { // 过滤掉对于文件总数的输出 continue } - l.parseFileInfo(item) + fileListResult = append(fileListResult, l.parseFileInfo(item)) } - return result, nil + return result, fileListResult } // parseFileInfo 解析文件信息 @@ -84,11 +84,12 @@ func (l *ls) Run() (*define.Result, []define.LsFileInfo) { // Author : go_developer@163.com<白茶清欢> // // 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, " ") - fmt.Println("文件信息 : ", fileInfoArr) - fmt.Println(l.getFilePermission(fileInfoArr[0])) - return nil + fileInfo := define.LsFileInfo{} + // 是否链接 / 是否目录 / 文件权限解析 + fileInfo.IsLink, fileInfo.IsDir, fileInfo.Permission = l.getFilePermission(fileInfoArr[0]) + return fileInfo } // getFilePermission 解析文件权限信息 , 根据 drwxrwxrwx 这个规范解析