diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-03-23 11:21:26 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-03-28 08:21:08 +0300 |
commit | 29f8e00ea172c962109d810ab3ad6d44093a6e15 (patch) | |
tree | 3ac024c5ba32364fcae58ad09bb1e061f9e7a4f3 | |
parent | 5dc37f2223bfa071e331383c07f5b4c0df48ed22 (diff) |
repository: Refactor `dirSizeInKB` to return bytes
The helper function `dirSizeInKB` returns kilobytes instead of bytes,
making it less useful in general. Convert the function to instead return
bytes and adapt its callers accordingly. This prepares for adding an
additional user to this function.
-rw-r--r-- | internal/gitaly/service/repository/size.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/internal/gitaly/service/repository/size.go b/internal/gitaly/service/repository/size.go index 52725ba81..195738e10 100644 --- a/internal/gitaly/service/repository/size.go +++ b/internal/gitaly/service/repository/size.go @@ -35,10 +35,12 @@ func (s *server) RepositorySize(ctx context.Context, in *gitalypb.RepositorySize var sizeKiB int64 if featureflag.RepositorySizeViaWalk.IsEnabled(ctx) { - sizeKiB, err = dirSizeInKB(path) + sizeBytes, err := dirSizeInBytes(path) if err != nil { return nil, fmt.Errorf("calculating directory size: %w", err) } + + sizeKiB = sizeBytes / 1024 } else { sizeKiB = getPathSize(ctx, path) } @@ -60,10 +62,12 @@ func (s *server) GetObjectDirectorySize(ctx context.Context, in *gitalypb.GetObj var sizeKiB int64 if featureflag.RepositorySizeViaWalk.IsEnabled(ctx) { - sizeKiB, err = dirSizeInKB(path) + sizeBytes, err := dirSizeInBytes(path) if err != nil { return nil, fmt.Errorf("calculating directory size: %w", err) } + + sizeKiB = sizeBytes / 1024 } else { sizeKiB = getPathSize(ctx, path) } @@ -104,7 +108,7 @@ func getPathSize(ctx context.Context, path string) int64 { return size } -func dirSizeInKB(path string) (int64, error) { +func dirSizeInBytes(path string) (int64, error) { var totalSize int64 if err := filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error { @@ -140,5 +144,5 @@ func dirSizeInKB(path string) (int64, error) { return 0, fmt.Errorf("walking directory: %w", err) } - return totalSize / 1024, nil + return totalSize, nil } |