From dab1247c83d503d38500aae1b8f5d413c44e3bb7 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Tue, 13 Aug 2024 23:01:19 +0200 Subject: [PATCH] chore(files): explicit 'not set' in missing stats --- core/commands/files.go | 27 ++++++++++++++++----------- test/sharness/t0047-add-mode-mtime.sh | 0 test/sharness/t0250-files-api.sh | 8 ++++---- 3 files changed, 20 insertions(+), 15 deletions(-) mode change 100644 => 100755 test/sharness/t0047-add-mode-mtime.sh diff --git a/core/commands/files.go b/core/commands/files.go index a8d6f1397c66..50f6ac1a15eb 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -160,6 +160,7 @@ Mtime: ` filesFormatOptionName = "format" filesSizeOptionName = "size" filesWithLocalOptionName = "with-local" + filesStatUnspecified = "not set" ) var filesStatCmd = &cmds.Command{ @@ -172,7 +173,8 @@ var filesStatCmd = &cmds.Command{ }, Options: []cmds.Option{ cmds.StringOption(filesFormatOptionName, "Print statistics in given format. Allowed tokens: "+ - " . Conflicts with other format options.").WithDefault(defaultStatFormat), + " and optional ."+ + "Conflicts with other format options.").WithDefault(defaultStatFormat), cmds.BoolOption(filesHashOptionName, "Print only hash. Implies '--format='. Conflicts with other format options."), cmds.BoolOption(filesSizeOptionName, "Print only size. Implies '--format='. Conflicts with other format options."), cmds.BoolOption(filesWithLocalOptionName, "Compute the amount of the dag that is local, and if possible the total size"), @@ -243,13 +245,16 @@ var filesStatCmd = &cmds.Command{ }, Encoders: cmds.EncoderMap{ cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *statOutput) error { - var mode os.FileMode + mode, modeo := filesStatUnspecified, filesStatUnspecified if out.Mode != 0 { - mode = os.FileMode(out.Mode) + mode = strings.ToLower(os.FileMode(out.Mode).String()) + modeo = "0" + strconv.FormatInt(int64(out.Mode&0x1FF), 8) } - var mtime string + mtime, mtimes, mtimens := filesStatUnspecified, filesStatUnspecified, filesStatUnspecified if out.Mtime > 0 { mtime = time.Unix(out.Mtime, int64(out.MtimeNsecs)).UTC().Format("2 Jan 2006, 15:04:05 MST") + mtimes = strconv.FormatInt(out.Mtime, 10) + mtimens = strconv.Itoa(out.MtimeNsecs) } s, _ := statGetFormatOptions(req) @@ -258,11 +263,11 @@ var filesStatCmd = &cmds.Command{ s = strings.Replace(s, "", fmt.Sprintf("%d", out.CumulativeSize), -1) s = strings.Replace(s, "", fmt.Sprintf("%d", out.Blocks), -1) s = strings.Replace(s, "", out.Type, -1) - s = strings.Replace(s, "", strings.ToLower(mode.String()), -1) + s = strings.Replace(s, "", mode, -1) + s = strings.Replace(s, "", modeo, -1) s = strings.Replace(s, "", mtime, -1) - s = strings.Replace(s, "", strconv.FormatInt(out.Mtime, 10), -1) - s = strings.Replace(s, "", strconv.Itoa(out.MtimeNsecs), -1) - s = strings.Replace(s, "", "0"+strconv.FormatInt(int64(out.Mode&0x1FF), 8), -1) + s = strings.Replace(s, "", mtimes, -1) + s = strings.Replace(s, "", mtimens, -1) fmt.Fprintln(w, s) @@ -1399,13 +1404,13 @@ The mode argument must be specified in Unix numeric notation. $ ipfs files stat /foo ... Type: file - Mode: -rw-r--r-- + Mode: -rw-r--r-- (0644) ... `, }, Arguments: []cmds.Argument{ - cmds.StringArg("mode", true, false, "mode to apply to node"), - cmds.StringArg("path", true, false, "Path to target node"), + cmds.StringArg("mode", true, false, "Mode to apply to node (numeric notation)"), + cmds.StringArg("path", true, false, "Path to apply mode"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { nd, err := cmdenv.GetNode(env) diff --git a/test/sharness/t0047-add-mode-mtime.sh b/test/sharness/t0047-add-mode-mtime.sh old mode 100644 new mode 100755 diff --git a/test/sharness/t0250-files-api.sh b/test/sharness/t0250-files-api.sh index abe21c43d03b..9c01a5bcf17e 100755 --- a/test/sharness/t0250-files-api.sh +++ b/test/sharness/t0250-files-api.sh @@ -230,8 +230,8 @@ test_files_api() { echo "Size: 4" >> file1stat_expect && echo "ChildBlocks: 0" >> file1stat_expect && echo "Type: file" >> file1stat_expect && - echo "Mode: ---------- (00)" >> file1stat_expect && - echo "Mtime: " >> file1stat_expect && + echo "Mode: not set (not set)" >> file1stat_expect && + echo "Mtime: not set" >> file1stat_expect && test_cmp file1stat_expect file1stat_actual ' @@ -245,8 +245,8 @@ test_files_api() { echo "Size: 4" >> file1stat_expect && echo "ChildBlocks: 0" >> file1stat_expect && echo "Type: file" >> file1stat_expect && - echo "Mode: ---------- (00)" >> file1stat_expect && - echo "Mtime: " >> file1stat_expect && + echo "Mode: not set (not set)" >> file1stat_expect && + echo "Mtime: not set" >> file1stat_expect && test_cmp file1stat_expect file1stat_actual '