-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload: scan the directory to be uploaded in parallel to estimate the…
… amount of data to be uploaded This allows better progress indicator in the CLI and UI. The percentage completed is not displayed until estimate is available. Quick demo: https://asciinema.org/a/O7ktcWSgaGUPfJwhzc65mMWM1
- Loading branch information
Showing
6 changed files
with
132 additions
and
31 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
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
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,51 @@ | ||
package snapshotfs | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/kopia/kopia/fs" | ||
) | ||
|
||
type scanResults struct { | ||
numFiles int | ||
totalFileSize int64 | ||
} | ||
|
||
// scanDirectory computes the number of files and their total size in a given directory recursively descending | ||
// into subdirectories. The scan teminates early as soon as the provided context is canceled. | ||
func (u *Uploader) scanDirectory(ctx context.Context, dir fs.Directory) (scanResults, error) { | ||
var res scanResults | ||
|
||
if u.disableEstimation { | ||
return res, nil | ||
} | ||
|
||
entries, err := dir.Readdir(ctx) | ||
if err != nil { | ||
return res, err | ||
} | ||
|
||
for _, e := range entries { | ||
if err := ctx.Err(); err != nil { | ||
// terminate early if context got canceled | ||
return res, err | ||
} | ||
|
||
switch e := e.(type) { | ||
case fs.Directory: | ||
dr, err := u.scanDirectory(ctx, e) | ||
res.numFiles += dr.numFiles | ||
res.totalFileSize += dr.totalFileSize | ||
|
||
if err != nil { | ||
return res, err | ||
} | ||
|
||
case fs.File: | ||
res.numFiles++ | ||
res.totalFileSize += e.Size() | ||
} | ||
} | ||
|
||
return res, nil | ||
} |
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