Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-29 21:26:10 +01:00

[GITEA] Ignore temporary files for directory size

- Backport https://codeberg.org/forgejo/forgejo/pulls/1742
  - While looking trough the logs for unrelated things I noticed errors
for directory size calculations in `pushUpdates` that were being caused
by a race condition in which git was making temporary file,
`filepath.WalkDir` noticed that but by the time the second lstat
came(`info.Info()`) it was already gone and it would error.
  - Ignore temporary files created by Git.
  - There are other cases but much much more rarer and not trivial to detect.

Examples:

...s/repository/push.go:96:pushUpdates() [E] Failed to update size for repository: updateSize: lstat [...]/objects/info/commit-graphs/tmp_graph_Wcy9kR: no such file or directory
...s/repository/push.go:96:pushUpdates() [E] Failed to update size for repository: updateSize: lstat [...]/packed-refs.lock: no such file or directory

(cherry picked from commit 16ce00772d)
(cherry picked from commit 2aebef847f)
This commit is contained in:
Gusted 2023-11-06 23:53:22 +01:00 committed by Earl Warren
parent 9080bb1fdc
commit 68dddcc6ff
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00

View file

@ -167,7 +167,11 @@ func getDirectorySize(path string) (int64, error) {
} }
return err return err
} }
if info.IsDir() {
fileName := info.Name()
// Ignore temporary Git files as they will like be missing once info.Info is
// called and cause a disrupt to the whole operation.
if info.IsDir() || strings.HasSuffix(fileName, ".lock") || strings.HasPrefix(filepath.Base(fileName), "tmp_graph") {
return nil return nil
} }
f, err := info.Info() f, err := info.Info()