File tree 4 files changed +26
-8
lines changed
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) {
60
60
}
61
61
62
62
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 )
64
64
if err != nil {
65
- log .Warn ("GetRepoSize : %v" , err )
65
+ log .Warn ("CountObjects : %v" , err )
66
66
continue
67
67
}
68
68
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import (
36
36
api "code.gitea.io/gitea/modules/structs"
37
37
"code.gitea.io/gitea/modules/sync"
38
38
"code.gitea.io/gitea/modules/timeutil"
39
+ "code.gitea.io/gitea/modules/util"
39
40
40
41
"github.com/mcuadros/go-version"
41
42
"github.com/unknwon/com"
@@ -708,17 +709,17 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
708
709
}
709
710
710
711
func (repo * Repository ) updateSize (e Engine ) error {
711
- repoInfoSize , err := git . GetRepoSize (repo .repoPath (e ))
712
+ size , err := util . GetDirectorySize (repo .repoPath (e ))
712
713
if err != nil {
713
714
return fmt .Errorf ("UpdateSize: %v" , err )
714
715
}
715
716
716
- repo .Size = repoInfoSize . Size + repoInfoSize . SizePack
717
+ repo .Size = size
717
718
_ , err = e .ID (repo .ID ).Cols ("size" ).Update (repo )
718
719
return err
719
720
}
720
721
721
- // UpdateSize updates the repository size, calculating it using git.GetRepoSize
722
+ // UpdateSize updates the repository size, calculating it using util.GetDirectorySize
722
723
func (repo * Repository ) UpdateSize () error {
723
724
return repo .updateSize (x )
724
725
}
Original file line number Diff line number Diff line change @@ -304,8 +304,8 @@ const (
304
304
statSizeGarbage = "size-garbage: "
305
305
)
306
306
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 ) {
309
309
cmd := NewCommand ("count-objects" , "-v" )
310
310
stdout , err := cmd .RunInDir (repoPath )
311
311
if err != nil {
Original file line number Diff line number Diff line change 4
4
5
5
package util
6
6
7
- import "path/filepath"
7
+ import (
8
+ "os"
9
+ "path/filepath"
10
+ )
8
11
9
12
// EnsureAbsolutePath ensure that a path is absolute, making it
10
13
// relative to absoluteBase if necessary
@@ -14,3 +17,17 @@ func EnsureAbsolutePath(path string, absoluteBase string) string {
14
17
}
15
18
return filepath .Join (absoluteBase , path )
16
19
}
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