diff options
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 6a92a2c0448..064b3c1fc23 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -352,14 +352,9 @@ class Project < ActiveRecord::Base joins(join_body).reorder('join_note_counts.amount DESC') end - def create_from_import_job(current_user_id:, tmp_file:, namespace_id:, project_path:) - job_id = ProjectImportWorker.perform_async(current_user_id, tmp_file, namespace_id, project_path) - - if job_id - Rails.logger.info "Import job started for export #{tmp_file} with job ID #{job_id}" - else - Rails.logger.error "Import job failed to start for #{tmp_file}" - end + # Deletes gitlab project export files older than 24 hours + def remove_gitlab_exports! + Gitlab::Popen.popen(%W(find #{Gitlab::ImportExport.storage_path} -not -path #{Gitlab::ImportExport.storage_path} -mmin +1440 -delete)) end end @@ -464,7 +459,7 @@ class Project < ActiveRecord::Base end def import? - external_import? || forked? + external_import? || forked? || gitlab_project_import? end def no_import? @@ -495,6 +490,10 @@ class Project < ActiveRecord::Base Gitlab::UrlSanitizer.new(import_url).masked_url end + def gitlab_project_import? + import_type == 'gitlab_project' + end + def check_limit unless creator.can_create_project? or namespace.kind == 'group' projects_limit = creator.projects_limit @@ -1091,8 +1090,8 @@ class Project < ActiveRecord::Base @errors = original_errors end - def add_export_job(current_user_id:) - job_id = ProjectExportWorker.perform_async(current_user_id, self.id) + def add_export_job(current_user:) + job_id = ProjectExportWorker.perform_async(current_user.id, self.id) if job_id Rails.logger.info "Export job started for project ID #{self.id} with job ID #{job_id}" @@ -1100,4 +1099,17 @@ class Project < ActiveRecord::Base Rails.logger.error "Export job failed to start for project ID #{self.id}" end end + + def export_path + File.join(Gitlab::ImportExport.storage_path, path_with_namespace) + end + + def export_project_path + Dir.glob("#{export_path}/*export.tar.gz").max_by { |f| File.ctime(f) } + end + + def remove_exports + _, status = Gitlab::Popen.popen(%W(find #{export_path} -not -path #{export_path} -delete)) + status.zero? + end end |