Skip to content

Commit

Permalink
feat: print uid/gid for the files in ls -l
Browse files Browse the repository at this point in the history
This adds information about file ownership in the long listing which is
crucial sometimes.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Aug 12, 2021
1 parent e6fa401 commit dadaa65
Show file tree
Hide file tree
Showing 7 changed files with 993 additions and 908 deletions.
4 changes: 4 additions & 0 deletions api/machine/machine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ message FileInfo {
string link = 8;
// RelativeName is the name of the file or directory relative to the RootPath
string relative_name = 9;
// Owner uid
uint32 uid = 10;
// Owner gid
uint32 gid = 11;
}

// DiskUsageInfo describes a file or directory's information for du command
Expand Down
6 changes: 4 additions & 2 deletions cmd/talosctl/cmd/talos/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var lsCmd = &cobra.Command{
}

w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
fmt.Fprintln(w, "NODE\tMODE\tSIZE(B)\tLASTMOD\tNAME")
fmt.Fprintln(w, "NODE\tMODE\tUID\tGID\tSIZE(B)\tLASTMOD\tNAME")
for {
info, err := stream.Recv()
if err != nil {
Expand Down Expand Up @@ -179,9 +179,11 @@ var lsCmd = &cobra.Command{
}
}

fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%s\t%d\t%d\t%s\t%s\t%s\n",
node,
os.FileMode(info.Mode).String(),
info.Uid,
info.Gid,
size,
timestampFormatted,
display,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ func (s *Server) List(req *machine.ListRequest, obj machine.MachineService_ListS
Modified: fi.FileInfo.ModTime().Unix(),
IsDir: fi.FileInfo.IsDir(),
Link: fi.Link,
Uid: fi.FileInfo.Sys().(*syscall.Stat_t).Uid,
Gid: fi.FileInfo.Sys().(*syscall.Stat_t).Gid,
})
}

Expand Down
2 changes: 1 addition & 1 deletion internal/integration/cli/diskusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (suite *DiskUsageSuite) TestSuccess() {

parts := splitLine(lines[1])
var err error
folderSize, err = strconv.ParseInt(parts[2], 10, 64)
folderSize, err = strconv.ParseInt(parts[4], 10, 64)
if err != nil {
return err
}
Expand Down
1,831 changes: 926 additions & 905 deletions pkg/machinery/api/machine/machine.pb.go

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions pkg/machinery/api/machine/machine_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions website/content/docs/v0.12/Reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ TODO: unix timestamp or include proto's Date type |
| error | [string](#string) | | Error describes any error encountered while trying to read the file information. |
| link | [string](#string) | | Link is filled with symlink target |
| relative_name | [string](#string) | | RelativeName is the name of the file or directory relative to the RootPath |
| uid | [uint32](#uint32) | | Owner uid |
| gid | [uint32](#uint32) | | Owner gid |



Expand Down

0 comments on commit dadaa65

Please sign in to comment.