2016-07-18 15:38:36 -04:00
|
|
|
class RepositoryArchiveCleanUpService
|
|
|
|
LAST_MODIFIED_TIME_IN_MINUTES = 120
|
|
|
|
|
2016-08-02 05:32:28 -04:00
|
|
|
attr_reader :mmin, :path
|
|
|
|
|
2016-07-18 15:38:36 -04:00
|
|
|
def initialize(mmin = LAST_MODIFIED_TIME_IN_MINUTES)
|
|
|
|
@mmin = mmin
|
|
|
|
@path = Gitlab.config.gitlab.repository_downloads_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
Gitlab::Metrics.measure(:repository_archive_clean_up) do
|
2018-04-18 05:19:40 -04:00
|
|
|
next unless File.directory?(path)
|
2016-07-18 15:38:36 -04:00
|
|
|
|
|
|
|
clean_up_old_archives
|
|
|
|
clean_up_empty_directories
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clean_up_old_archives
|
2018-04-25 04:22:43 -04:00
|
|
|
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))
|
2016-07-18 15:38:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def clean_up_empty_directories
|
2018-04-25 04:22:43 -04:00
|
|
|
run(%W(find #{path} -mindepth 2 -maxdepth 2 -type d -empty -delete))
|
|
|
|
run(%W(find #{path} -mindepth 1 -maxdepth 1 -type d -empty -delete))
|
2016-07-18 15:38:36 -04:00
|
|
|
end
|
|
|
|
|
2016-07-20 19:29:25 -04:00
|
|
|
def run(cmd)
|
|
|
|
Gitlab::Popen.popen(cmd)
|
2016-07-18 15:38:36 -04:00
|
|
|
end
|
|
|
|
end
|