|
@@ -2,25 +2,40 @@ package main
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
- "os/exec"
|
|
|
+ "os"
|
|
|
"strconv"
|
|
|
- "strings"
|
|
|
)
|
|
|
|
|
|
func GetDirectoryDiskUsed(directories []string) (uint64, error) {
|
|
|
- cmd := exec.Command("du", "-s")
|
|
|
- cmd.Args = append(cmd.Args, directories...)
|
|
|
- output, err := cmd.CombinedOutput()
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- return 0, err
|
|
|
- }
|
|
|
- lines := strings.Split(string(output), "\n")
|
|
|
- fmt.Println(lines)
|
|
|
+ //cmd := exec.Command("du", "-s")
|
|
|
+ //cmd.Args = append(cmd.Args, directories...)
|
|
|
+ //output, err := cmd.CombinedOutput()
|
|
|
+ //if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // return 0, err
|
|
|
+ //}
|
|
|
+ //lines := strings.Split(string(output), "\n")
|
|
|
+ //fmt.Println(lines)
|
|
|
+ //sum := uint64(0)
|
|
|
+ //for _, line := range lines {
|
|
|
+ // fields := strings.Fields(line)
|
|
|
+ // parseUint, err := strconv.ParseUint(fields[0], 10, 64)
|
|
|
+ // fmt.Println("parseUint", parseUint)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println(err)
|
|
|
+ // return 0, err
|
|
|
+ // }
|
|
|
+ // sum += parseUint
|
|
|
+ //}
|
|
|
sum := uint64(0)
|
|
|
- for _, line := range lines {
|
|
|
- fields := strings.Fields(line)
|
|
|
- parseUint, err := strconv.ParseUint(fields[0], 10, 64)
|
|
|
+ for _, directory := range directories {
|
|
|
+ fileInfo, err := os.Stat(directory)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ return 0, err
|
|
|
+ }
|
|
|
+ fmt.Println("fileInfo.Size()", fileInfo.Size())
|
|
|
+ parseUint, err := strconv.ParseUint(strconv.FormatInt(fileInfo.Size(), 10), 10, 64)
|
|
|
fmt.Println("parseUint", parseUint)
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|