Skip to content

Commit

Permalink
ls: update --show-fullpath flag (peak#601)
Browse files Browse the repository at this point in the history
The flag now shows the date, ETag etc. of the objects.

Updates peak#596 .
  • Loading branch information
denizsurmeli committed Jul 24, 2023
1 parent ef362f3 commit 4f54f64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
12 changes: 10 additions & 2 deletions command/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Examples:
10. List all versions of all objects in the bucket
> s5cmd {{.HelpName}} --all-versions "s3://bucket/*"
11. List all files only with their fullpaths
11. List all files with their fullpaths
> s5cmd {{.HelpName}} --show-fullpath "s3://bucket/*"
`
Expand Down Expand Up @@ -292,13 +292,21 @@ func (l ListMessage) String() string {
if l.showStorageClass {
stclass = fmt.Sprintf("%v", l.Object.StorageClass)
}

var path string
if l.showFullPath {
path = l.Object.URL.String()
} else {
path = l.Object.URL.Relative()
}

s = fmt.Sprintf(
listFormat,
l.Object.ModTime.Format(dateFormat),
stclass,
etag,
l.humanize(),
l.Object.URL.Relative(),
path,
l.Object.URL.VersionID,
)

Expand Down
20 changes: 10 additions & 10 deletions e2e/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,16 @@ func TestListS3ObjectsAndFoldersWithTheirFullpath(t *testing.T) {

// assert lexical order
assertLines(t, result.Stdout(), map[int]compareFunc{
0: equals("s3://%v/a/testfile2.txt", bucket),
1: equals("s3://%v/b/testfile3.txt", bucket),
2: equals("s3://%v/b/testfile4.txt", bucket),
3: equals("s3://%v/c/testfile5.gz", bucket),
4: equals("s3://%v/d/foo/bar/file7.txt", bucket),
5: equals("s3://%v/d/foo/bar/testfile8.txt", bucket),
6: equals("s3://%v/e/txt/testfile9.txt.gz", bucket),
7: equals("s3://%v/f/txt/testfile10.txt", bucket),
8: equals("s3://%v/report.gz", bucket),
9: equals("s3://%v/testfile1.txt", bucket),
0: suffix("s3://%v/a/testfile2.txt", bucket),
1: suffix("s3://%v/b/testfile3.txt", bucket),
2: suffix("s3://%v/b/testfile4.txt", bucket),
3: suffix("s3://%v/c/testfile5.gz", bucket),
4: suffix("s3://%v/d/foo/bar/file7.txt", bucket),
5: suffix("s3://%v/d/foo/bar/testfile8.txt", bucket),
6: suffix("s3://%v/e/txt/testfile9.txt.gz", bucket),
7: suffix("s3://%v/f/txt/testfile10.txt", bucket),
8: suffix("s3://%v/report.gz", bucket),
9: suffix("s3://%v/testfile1.txt", bucket),
}, alignment(true))
}

Expand Down

0 comments on commit 4f54f64

Please sign in to comment.