Commit 24e5fbe6 authored by Kevin Atkinson's avatar Kevin Atkinson

Only display "Calculating ..." msg if calculation takes more then 5 sec.

parent 903d4a77
...@@ -27,8 +27,9 @@ var log = logging.Logger("flatfs") ...@@ -27,8 +27,9 @@ var log = logging.Logger("flatfs")
const ( const (
extension = ".data" extension = ".data"
diskUsageMessageTimeout = 5 * time.Second
diskUsageCheckpointPercent = 1.0 diskUsageCheckpointPercent = 1.0
diskUsageCheckpointTimeout = 2.0 * time.Second diskUsageCheckpointTimeout = 2 * time.Second
) )
var ( var (
...@@ -761,12 +762,21 @@ func (fs *Datastore) calculateDiskUsage() error { ...@@ -761,12 +762,21 @@ func (fs *Datastore) calculateDiskUsage() error {
return nil return nil
} }
fmt.Printf("Calculating datastore size. This might take %s at most and will happen only once\n", DiskUsageCalcTimeout.String()) msgDone := make(chan struct{}, 1) // prevent race condition
msgTimer := time.AfterFunc(diskUsageMessageTimeout, func() {
fmt.Printf("Calculating datastore size. This might take %s at most and will happen only once\n",
DiskUsageCalcTimeout.String())
msgDone <- struct{}{}
})
defer msgTimer.Stop()
deadline := time.Now().Add(DiskUsageCalcTimeout) deadline := time.Now().Add(DiskUsageCalcTimeout)
du, accuracy, err := folderSize(fs.path, deadline) du, accuracy, err := folderSize(fs.path, deadline)
if err != nil { if err != nil {
return err return err
} }
if !msgTimer.Stop() {
<-msgDone
}
if accuracy == timedoutA { if accuracy == timedoutA {
fmt.Println("WARN: It took to long to calculate the datastore size") fmt.Println("WARN: It took to long to calculate the datastore size")
fmt.Printf("WARN: The total size (%d) is an estimation. You can fix errors by\n", du) fmt.Printf("WARN: The total size (%d) is an estimation. You can fix errors by\n", du)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment