diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /app/services/import_export_clean_up_service.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'app/services/import_export_clean_up_service.rb')
-rw-r--r-- | app/services/import_export_clean_up_service.rb | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/app/services/import_export_clean_up_service.rb b/app/services/import_export_clean_up_service.rb index 66ac7dac4ca..567ac065cf7 100644 --- a/app/services/import_export_clean_up_service.rb +++ b/app/services/import_export_clean_up_service.rb @@ -2,6 +2,7 @@ class ImportExportCleanUpService LAST_MODIFIED_TIME_IN_MINUTES = 1440 + DIR_DEPTH = 5 attr_reader :mmin, :path @@ -27,15 +28,42 @@ class ImportExportCleanUpService end def clean_up_export_files - Gitlab::Popen.popen(%W(find #{path} -not -path #{path} -mmin +#{mmin} -delete)) + old_directories do |dir| + FileUtils.remove_entry(dir) + + logger.info( + message: 'Removed Import/Export tmp directory', + dir_path: dir + ) + end end - # rubocop: disable CodeReuse/ActiveRecord def clean_up_export_object_files - ImportExportUpload.where('updated_at < ?', mmin.minutes.ago).each do |upload| + ImportExportUpload.with_export_file.updated_before(mmin.minutes.ago).each do |upload| upload.remove_export_file! upload.save! + + logger.info( + message: 'Removed Import/Export export_file', + project_id: upload.project_id, + group_id: upload.group_id + ) + end + end + + def old_directories + IO.popen(directories_cmd) do |find| + find.each_line(chomp: true) do |directory| + yield directory + end end end - # rubocop: enable CodeReuse/ActiveRecord + + def directories_cmd + %W(find #{path} -mindepth #{DIR_DEPTH} -maxdepth #{DIR_DEPTH} -type d -not -path #{path} -mmin +#{mmin}) + end + + def logger + @logger ||= Gitlab::Import::Logger.build + end end |