MCPcopy Index your code
hub / github.com/docker/cli / localContentSize

Function localContentSize

cli/command/container/cp.go:174–200  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
174func 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.

Callers 1

copyToContainerFunction · 0.85

Calls 4

ModeMethod · 0.80
SizeMethod · 0.45
TypeMethod · 0.45
InfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…