Skip to content

Commit

Permalink
Add RootDirFileSizeInBytes utility function (#120)
Browse files Browse the repository at this point in the history
RootDirFileSizeInBytes function returns the sum of every file size
in multi-wallet directory.
  • Loading branch information
beansgum authored Mar 18, 2020
1 parent cfbcc29 commit d115352
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions multiwallet_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package dcrlibwallet

import (
"context"
"os"
"path/filepath"

"github.com/asdine/storm"
"github.com/decred/dcrwallet/errors/v2"
Expand Down Expand Up @@ -98,3 +100,19 @@ func (mw *MultiWallet) setNetworkBackend(syncer *spv.Syncer) {
}
}
}

// RootDirFileSizeInBytes returns the total directory size of
// multiwallet's root directory in bytes.
func (mw *MultiWallet) RootDirFileSizeInBytes() (int64, error) {
var size int64
err := filepath.Walk(mw.rootDir, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += info.Size()
}
return err
})
return size, err
}

0 comments on commit d115352

Please sign in to comment.