localContentSize returns the total size of regular file content at path. For a regular file it returns the file size. For a directory it walks the tree and sums sizes of all regular files.
(path string)
| 172 | // For a regular file it returns the file size. For a directory it walks |
| 173 | // the tree and sums sizes of all regular files. |
| 174 | func localContentSize(path string) (int64, error) { |
| 175 | fi, err := os.Lstat(path) |
| 176 | if err != nil { |
| 177 | return -1, err |
| 178 | } |
| 179 | if !fi.IsDir() { |
| 180 | if fi.Mode().IsRegular() { |
| 181 | return fi.Size(), nil |
| 182 | } |
| 183 | return 0, nil |
| 184 | } |
| 185 | var total int64 |
| 186 | err = filepath.WalkDir(path, func(_ string, d os.DirEntry, err error) error { |
| 187 | if err != nil { |
| 188 | return err |
| 189 | } |
| 190 | if d.Type().IsRegular() { |
| 191 | info, err := d.Info() |
| 192 | if err != nil { |
| 193 | return err |
| 194 | } |
| 195 | total += info.Size() |
| 196 | } |
| 197 | return nil |
| 198 | }) |
| 199 | return total, err |
| 200 | } |
| 201 | |
| 202 | // copySummary formats the "Successfully copied ..." message. |
| 203 | // When contentSize differs from transferredSize, both values are shown. |
no test coverage detected
searching dependent graphs…