-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Colm Dougan
committed
Apr 9, 2022
1 parent
1dee011
commit 21f6d51
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const SNAPSHOT_FORMAT = "%18d %24d %24s %28s \n" | ||
|
||
func count(args []string, humanReadable bool) { | ||
if len(args) == 0 { | ||
fatalWithUsage() | ||
} | ||
|
||
expanded, client, err := getClientAndExpandedPaths(args) | ||
if err != nil { | ||
fatal(err) | ||
} | ||
|
||
for _, p := range expanded { | ||
_, err := client.Stat(p) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
status = 1 | ||
continue | ||
} | ||
|
||
cs, err := client.GetContentSummary(p) | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
status = 1 | ||
continue | ||
} | ||
|
||
contentSize := formatBytesHuman(uint64(cs.Size()), humanReadable) | ||
fmt.Printf(SNAPSHOT_FORMAT, cs.DirectoryCount(), cs.FileCount(), contentSize, p) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bats | ||
|
||
load helper | ||
|
||
setup() { | ||
$HDFS mkdir -p /_test_cmd/count/dir1 | ||
$HDFS mkdir -p /_test_cmd/count/dir2 | ||
$HDFS mkdir -p /_test_cmd/count/dir3 | ||
$HDFS put $ROOT_TEST_DIR/testdata/foo.txt /_test_cmd/count/foo.txt | ||
$HDFS put $ROOT_TEST_DIR/testdata/foo.txt /_test_cmd/count/dir1/foo1.txt | ||
} | ||
|
||
@test "count" { | ||
run $HDFS count /_test_cmd/count/foo.txt | ||
assert_success | ||
assert_output <<OUT | ||
0 1 4 /_test_cmd/count/foo.txt | ||
OUT | ||
} | ||
|
||
@test "count human readable" { | ||
run $HDFS count -h /_test_cmd/count/foo.txt | ||
assert_success | ||
assert_output <<OUT | ||
0 1 4B /_test_cmd/count/foo.txt | ||
OUT | ||
} | ||
|
||
@test "count dir" { | ||
run $HDFS count /_test_cmd/count | ||
assert_success | ||
assert_output <<OUT | ||
4 2 8 /_test_cmd/count | ||
OUT | ||
} | ||
|
||
@test "count wildcard" { | ||
run $HDFS count /_test_cmd/count/dir* | ||
assert_success | ||
assert_output <<OUT | ||
1 1 4 /_test_cmd/count/dir1 | ||
1 0 0 /_test_cmd/count/dir2 | ||
1 0 0 /_test_cmd/count/dir3 | ||
OUT | ||
} | ||
|
||
@test "count nonexistent" { | ||
run $HDFS count /_test_cmd/nonexistent | ||
assert_failure | ||
assert_output <<OUT | ||
stat /_test_cmd/nonexistent: file does not exist | ||
OUT | ||
} | ||
|
||
teardown() { | ||
$HDFS rm -r /_test_cmd/count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters