diff options
Diffstat (limited to 'app/services/repository_archive_clean_up_service.rb')
-rw-r--r-- | app/services/repository_archive_clean_up_service.rb | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/app/services/repository_archive_clean_up_service.rb b/app/services/repository_archive_clean_up_service.rb index 99a9c834352..0fb7dfdb85f 100644 --- a/app/services/repository_archive_clean_up_service.rb +++ b/app/services/repository_archive_clean_up_service.rb @@ -1,8 +1,23 @@ # frozen_string_literal: true +# RepositoryArchiveCleanUpService removes cached repository archives +# that are generated on-the-fly by Gitaly. These files are stored in the +# following form (as defined in lib/gitlab/git/repository.rb) and served +# by GitLab Workhorse: +# +# /path/to/repository/downloads/project-N/sha/@v2/archive.format +# +# Legacy paths omit the @v2 prefix. +# +# For example: +# +# /var/opt/gitlab/gitlab-rails/shared/cache/archive/project-1/master/@v2/archive.zip class RepositoryArchiveCleanUpService LAST_MODIFIED_TIME_IN_MINUTES = 120 + # For `/path/project-N/sha/@v2/archive.zip`, `find /path -maxdepth 4` will find this file + MAX_ARCHIVE_DEPTH = 4 + attr_reader :mmin, :path def initialize(mmin = LAST_MODIFIED_TIME_IN_MINUTES) @@ -22,12 +37,15 @@ class RepositoryArchiveCleanUpService private def clean_up_old_archives - run(%W(find #{path} -mindepth 1 -maxdepth 3 -type f \( -name \*.tar -o -name \*.bz2 -o -name \*.tar.gz -o -name \*.zip \) -mmin +#{mmin} -delete)) + run(%W(find #{path} -mindepth 1 -maxdepth #{MAX_ARCHIVE_DEPTH} -type f \( -name \*.tar -o -name \*.bz2 -o -name \*.tar.gz -o -name \*.zip \) -mmin +#{mmin} -delete)) end def clean_up_empty_directories - run(%W(find #{path} -mindepth 2 -maxdepth 2 -type d -empty -delete)) - run(%W(find #{path} -mindepth 1 -maxdepth 1 -type d -empty -delete)) + (1...MAX_ARCHIVE_DEPTH).reverse_each { |depth| clean_up_empty_directories_with_depth(depth) } + end + + def clean_up_empty_directories_with_depth(depth) + run(%W(find #{path} -mindepth #{depth} -maxdepth #{depth} -type d -empty -delete)) end def run(cmd) |