Skip to content

Commit

Permalink
ios: remove unused functions
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
VirrageS authored and alex-aizman committed Jun 13, 2024
1 parent c331cf2 commit d40b973
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 73 deletions.
47 changes: 0 additions & 47 deletions ios/fsutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,6 @@ func TestDirSize(t *testing.T) {
}
}

func TestDirFiles(t *testing.T) {
name, err := os.MkdirTemp("/tmp", t.Name())
if err != nil {
t.Error(err)
return
}
defer os.RemoveAll(name)

checkFileCount(t, name, 0)

subdir, err := os.MkdirTemp(name, "")
if err != nil {
t.Error(err)
return
}

checkFileCount(t, name, 0)

size := mkFile(t, name, "f1.txt")
checkFileCount(t, name, 1)

size += mkFile(t, subdir, "f2.txt")
size += mkFile(t, subdir, "f3.txt")
checkFileCount(t, name, 3)
checkFileSizes(t, name, size)
}

func mkFile(t *testing.T, dir, fname string) (written int) {
k := mono.NanoTime() & 0xff
f, err := os.Create(path.Join(dir, fname))
Expand All @@ -89,23 +62,3 @@ func mkFile(t *testing.T, dir, fname string) (written int) {
}
return
}

func checkFileCount(t *testing.T, dir string, expcnt int) {
fileCount, err := ios.DirFileCount(dir)
if err != nil {
t.Error(err)
}
if fileCount != expcnt {
t.Fatalf("Expected %d files, got %d", expcnt, fileCount)
}
}

func checkFileSizes(t *testing.T, dir string, expsize int) {
size, err := ios.DirSumFileSizes(dir)
if err != nil {
t.Error(err)
}
if size != uint64(expsize) {
t.Fatalf("Expected %d size, got %d", expsize, size)
}
}
26 changes: 0 additions & 26 deletions ios/fsutils_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,3 @@ func _parseTotal(s string) (size int64) {
}
return
}

func DirFileCount(dirPath string) (int, error) {
cmd := fmt.Sprintf("find %s -type f | wc -l", dirPath)
outputBytes, err := exec.Command("/bin/sh", "-c", cmd).Output()
out := string(outputBytes)
if err != nil || out == "" {
return 0, fmt.Errorf("failed to count the number of files in %q: %v", dirPath, err)
}
out = strings.TrimSpace(out)
return strconv.Atoi(out)
}

func DirSumFileSizes(dirPath string) (uint64, error) {
cmd := fmt.Sprintf("find %s -type f | xargs wc -c | tail -1", dirPath)
outputBytes, err := exec.Command("/bin/sh", "-c", cmd).Output()
out := string(outputBytes)
if err != nil || out == "" {
return 0, fmt.Errorf("failed to correctly sum file sizes in %q: %v", dirPath, err)
}
i := strings.IndexByte(out, ' ')
if i < 0 {
debug.Assertf(out[0] == '0', "failed to sum file sizes in %q: [%s]", dirPath, out)
return 0, nil
}
return strconv.ParseUint(out[:i], 10, 0)
}

0 comments on commit d40b973

Please sign in to comment.