File tree Expand file tree Collapse file tree 4 files changed +26
-8
lines changed Expand file tree Collapse file tree 4 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -60,9 +60,9 @@ func addRepoSize(x *xorm.Engine) (err error) {
6060 }
6161
6262 repoPath := filepath .Join (setting .RepoRootPath , strings .ToLower (user .Name ), strings .ToLower (repo .Name )) + ".git"
63- countObject , err := git .GetRepoSize (repoPath )
63+ countObject , err := git .CountObjects (repoPath )
6464 if err != nil {
65- log .Warn ("GetRepoSize : %v" , err )
65+ log .Warn ("CountObjects : %v" , err )
6666 continue
6767 }
6868
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import (
3636 api "code.gitea.io/gitea/modules/structs"
3737 "code.gitea.io/gitea/modules/sync"
3838 "code.gitea.io/gitea/modules/timeutil"
39+ "code.gitea.io/gitea/modules/util"
3940
4041 "github.com/mcuadros/go-version"
4142 "github.com/unknwon/com"
@@ -708,17 +709,17 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
708709}
709710
710711func (repo * Repository ) updateSize (e Engine ) error {
711- repoInfoSize , err := git . GetRepoSize (repo .repoPath (e ))
712+ size , err := util . GetDirectorySize (repo .repoPath (e ))
712713 if err != nil {
713714 return fmt .Errorf ("UpdateSize: %v" , err )
714715 }
715716
716- repo .Size = repoInfoSize . Size + repoInfoSize . SizePack
717+ repo .Size = size
717718 _ , err = e .ID (repo .ID ).Cols ("size" ).Update (repo )
718719 return err
719720}
720721
721- // UpdateSize updates the repository size, calculating it using git.GetRepoSize
722+ // UpdateSize updates the repository size, calculating it using util.GetDirectorySize
722723func (repo * Repository ) UpdateSize () error {
723724 return repo .updateSize (x )
724725}
Original file line number Diff line number Diff line change @@ -304,8 +304,8 @@ const (
304304 statSizeGarbage = "size-garbage: "
305305)
306306
307- // GetRepoSize returns disk consumption for repo in path
308- func GetRepoSize (repoPath string ) (* CountObject , error ) {
307+ // CountObjects returns the results of git count-objects on the repoPath
308+ func CountObjects (repoPath string ) (* CountObject , error ) {
309309 cmd := NewCommand ("count-objects" , "-v" )
310310 stdout , err := cmd .RunInDir (repoPath )
311311 if err != nil {
Original file line number Diff line number Diff line change 44
55package util
66
7- import "path/filepath"
7+ import (
8+ "os"
9+ "path/filepath"
10+ )
811
912// EnsureAbsolutePath ensure that a path is absolute, making it
1013// relative to absoluteBase if necessary
@@ -14,3 +17,17 @@ func EnsureAbsolutePath(path string, absoluteBase string) string {
1417 }
1518 return filepath .Join (absoluteBase , path )
1619}
20+
21+ const notRegularFileMode os.FileMode = os .ModeDir | os .ModeSymlink | os .ModeNamedPipe | os .ModeSocket | os .ModeDevice | os .ModeCharDevice | os .ModeIrregular
22+
23+ // GetDirectorySize returns the dumb disk consumption for a given path
24+ func GetDirectorySize (path string ) (int64 , error ) {
25+ var size int64
26+ err := filepath .Walk (path , func (_ string , info os.FileInfo , err error ) error {
27+ if info != nil && (info .Mode ()& notRegularFileMode ) == 0 {
28+ size += info .Size ()
29+ }
30+ return err
31+ })
32+ return size , err
33+ }
You can’t perform that action at this time.
0 commit comments