summaryrefslogtreecommitdiffstats
path: root/modules/repository
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-11-29 13:08:58 +0800
committerGitHub <noreply@github.com>2023-11-29 13:08:58 +0800
commitb348424c64cb839f1a2dff8f14d4f99969ad2b5f (patch)
tree0bb40c52bc4268a44cfd513055eab5ebd5d3be0c /modules/repository
parent64cd6e8df5948c5c6b207e42e2e034e8d9bbc11d (diff)
downloadgitea-b348424c64cb839f1a2dff8f14d4f99969ad2b5f.tar.gz
gitea-b348424c64cb839f1a2dff8f14d4f99969ad2b5f.zip
Ignore "non-existing" errors when getDirectorySize calculates the size (#28276)
The git command may operate the git directory (add/remove) files in any time. So when the code iterates the directory, some files may disappear during the "walk". All "IsNotExist" errors should be ignored. Fix #26765
Diffstat (limited to 'modules/repository')
-rw-r--r--modules/repository/create.go27
1 files changed, 12 insertions, 15 deletions
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 153686089c..7c954a1412 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -160,28 +160,25 @@ const notRegularFileMode = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | o
// 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
- }
+ err := filepath.WalkDir(path, func(_ string, entry os.DirEntry, err error) error {
+ if os.IsNotExist(err) { // ignore the error because some files (like temp/lock file) may be deleted during traversing.
+ return nil
+ } else if err != nil {
return err
}
-
- 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") {
+ if entry.IsDir() {
return nil
}
- f, err := info.Info()
- if err != nil {
+ info, err := entry.Info()
+ if os.IsNotExist(err) { // ignore the error as above
+ return nil
+ } else if err != nil {
return err
}
- if (f.Mode() & notRegularFileMode) == 0 {
- size += f.Size()
+ if (info.Mode() & notRegularFileMode) == 0 {
+ size += info.Size()
}
- return err
+ return nil
})
return size, err
}