diff --git a/docs/content/doc/advanced/external-renderers.en-us.md b/docs/content/doc/advanced/external-renderers.en-us.md
index f40c23dd84..244fcd7c83 100644
--- a/docs/content/doc/advanced/external-renderers.en-us.md
+++ b/docs/content/doc/advanced/external-renderers.en-us.md
@@ -192,5 +192,5 @@ And so you could write some CSS:
Add your stylesheet to your custom directory e.g `custom/public/css/my-style-XXXXX.css` and import it using a custom header file `custom/templates/custom/header.tmpl`:
```html
-
+
```
diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml
index 19b243fb4e..5d4781ad44 100644
--- a/models/fixtures/repository.yml
+++ b/models/fixtures/repository.yml
@@ -24,7 +24,7 @@
fork_id: 0
is_template: false
template_id: 0
- size: 0
+ size: 6708
is_fsck_enabled: true
close_issues_via_commit_in_any_branch: false
diff --git a/models/repo/update.go b/models/repo/update.go
index 3aef280ff8..8dd1097450 100644
--- a/models/repo/update.go
+++ b/models/repo/update.go
@@ -184,7 +184,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s
return committer.Commit()
}
-// UpdateRepoSize updates the repository size, calculating it using util.GetDirectorySize
+// UpdateRepoSize updates the repository size, calculating it using getDirectorySize
func UpdateRepoSize(ctx context.Context, repoID, size int64) error {
_, err := db.GetEngine(ctx).ID(repoID).Cols("size").NoAutoTime().Update(&Repository{
Size: size,
diff --git a/modules/markup/external/external.go b/modules/markup/external/external.go
index f47776690f..ffbb6da4da 100644
--- a/modules/markup/external/external.go
+++ b/modules/markup/external/external.go
@@ -4,6 +4,7 @@
package external
import (
+ "bytes"
"fmt"
"io"
"os"
@@ -132,11 +133,13 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
if !p.IsInputFile {
cmd.Stdin = input
}
+ var stderr bytes.Buffer
cmd.Stdout = output
+ cmd.Stderr = &stderr
process.SetSysProcAttribute(cmd)
if err := cmd.Run(); err != nil {
- return fmt.Errorf("%s render run command %s %v failed: %w", p.Name(), commands[0], args, err)
+ return fmt.Errorf("%s render run command %s %v failed: %w\nStderr: %s", p.Name(), commands[0], args, err, stderr.String())
}
return nil
}
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 423250add3..04bc72c269 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path"
+ "path/filepath"
"strings"
"code.gitea.io/gitea/models"
@@ -287,9 +288,36 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
return repo, nil
}
-// UpdateRepoSize updates the repository size, calculating it using util.GetDirectorySize
+const notRegularFileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice | os.ModeCharDevice | os.ModeIrregular
+
+// getDirectorySize returns the disk consumption for a given path
+func getDirectorySize(path string) (int64, error) {
+ var size int64
+ err := filepath.WalkDir(path, func(_ string, info os.DirEntry, err error) error {
+ if err != nil {
+ if os.IsNotExist(err) { // ignore the error because the file maybe deleted during traversing.
+ return nil
+ }
+ return err
+ }
+ if info.IsDir() {
+ return nil
+ }
+ f, err := info.Info()
+ if err != nil {
+ return err
+ }
+ if (f.Mode() & notRegularFileMode) == 0 {
+ size += f.Size()
+ }
+ return err
+ })
+ return size, err
+}
+
+// UpdateRepoSize updates the repository size, calculating it using getDirectorySize
func UpdateRepoSize(ctx context.Context, repo *repo_model.Repository) error {
- size, err := util.GetDirectorySize(repo.RepoPath())
+ size, err := getDirectorySize(repo.RepoPath())
if err != nil {
return fmt.Errorf("updateSize: %w", err)
}
diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go
index da4a738b64..293071bdce 100644
--- a/modules/repository/create_test.go
+++ b/modules/repository/create_test.go
@@ -168,3 +168,13 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
assert.NoError(t, err)
assert.True(t, act.IsPrivate)
}
+
+func TestGetDirectorySize(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ repo, err := repo_model.GetRepositoryByID(db.DefaultContext, 1)
+ assert.NoError(t, err)
+
+ size, err := getDirectorySize(repo.RepoPath())
+ assert.NoError(t, err)
+ assert.EqualValues(t, size, repo.Size)
+}
diff --git a/modules/util/path.go b/modules/util/path.go
index 03013f7133..e060b527f3 100644
--- a/modules/util/path.go
+++ b/modules/util/path.go
@@ -22,20 +22,6 @@ func EnsureAbsolutePath(path, absoluteBase string) string {
return filepath.Join(absoluteBase, path)
}
-const notRegularFileMode os.FileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice | os.ModeCharDevice | os.ModeIrregular
-
-// GetDirectorySize returns the disk consumption for a given path
-func GetDirectorySize(path string) (int64, error) {
- var size int64
- err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
- if info != nil && (info.Mode()¬RegularFileMode) == 0 {
- size += info.Size()
- }
- return err
- })
- return size, err
-}
-
// IsDir returns true if given path is a directory,
// or returns false when it's a file or does not exist.
func IsDir(dir string) (bool, error) {