2016-07-18 15:38:36 -04:00
|
|
|
class RepositoryArchiveCleanUpService
|
|
|
|
LAST_MODIFIED_TIME_IN_MINUTES = 120
|
|
|
|
|
|
|
|
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
|
|
|
|
return unless File.directory?(path)
|
|
|
|
|
|
|
|
clean_up_old_archives
|
|
|
|
clean_up_empty_directories
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :mmin, :path
|
|
|
|
|
|
|
|
def clean_up_old_archives
|
2016-07-20 19:29:25 -04:00
|
|
|
run(%W(find #{path} -not -path #{path} -type f \( -name \*.tar -o -name \*.bz2 -o -name \*.tar.gz -o -name \*.zip \) -maxdepth 2 -mmin +#{mmin} -delete))
|
2016-07-18 15:38:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def clean_up_empty_directories
|
2016-07-20 19:29:25 -04:00
|
|
|
run(%W(find #{path} -not -path #{path} -type d -empty -name \*.git -maxdepth 1 -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
|