Skip to content

repository: Refactor RepositorySize to not rely on du(1)

One of the ways to calculate the repository size is to simply invoke the du(1) executability to calculate the size for us. This does not make a ton of sense though:

- It adds a dependency on an external program.

- This external program may behave differently depending on the
  platform.

- We need to spawn an executable, which can be expensive at times.

- Go already provides us with an easy way to implement the
  functionality ourselves via `filepath.WalkDir()`.

Refactor the code to implement the functionality ourselves. It is more efficient, easier to understand, has less platform-specific behaviour and has less external dependencies.

Note that due to different rounding behaviour between du(1) and our own implementation, we have to increase the size of test data we are writing in one of our tests.

Edited by Patrick Steinhardt

Merge request reports