From c5bc262981a9fbfe748dfb0b527e4fb0fa597ccf Mon Sep 17 00:00:00 2001
From: James Lopez <james@jameslopez.es>
Date: Thu, 28 Apr 2016 18:00:30 +0200
Subject: [PATCH] few fixes - import from UI working

---
 app/controllers/projects_controller.rb                | 4 +++-
 app/services/projects/import_export/export_service.rb | 2 +-
 lib/gitlab/import_export/command_line_util.rb         | 2 +-
 lib/gitlab/import_export/saver.rb                     | 1 +
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 1d4684ca22e..62f8b376c18 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -191,6 +191,7 @@ class ProjectsController < Projects::ApplicationController
   end
 
   def export
+    #TODO:  Move to worker
     ::Projects::ImportExport::ExportService.new(@project, current_user).execute
 
     redirect_to(
@@ -267,6 +268,7 @@ class ProjectsController < Projects::ApplicationController
 
   def export_project_path
     # TODO: move this, probably to ImportExport and refactor
-    File.join(Settings.shared['path'], 'tmp/project_exports', @project.path_with_namespace, 'project.tar.gz')
+    folder = File.join(Settings.shared['path'], 'tmp/project_exports', @project.path_with_namespace)
+    Dir.glob("#{folder}/*export.tar.gz").max_by {|f| File.ctime(f)}
   end
 end
diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb
index 8b641008a88..5d5573cba5c 100644
--- a/app/services/projects/import_export/export_service.rb
+++ b/app/services/projects/import_export/export_service.rb
@@ -3,7 +3,7 @@ module Projects
     class ExportService < BaseService
 
       def execute(options = {})
-        @shared = Gitlab::ImportExport::Shared.new(relative_path: project.path_with_namespace)
+        @shared = Gitlab::ImportExport::Shared.new(relative_path: File.join(project.path_with_namespace, 'work'))
         save_project_tree
         bundle_repo
         save_all
diff --git a/lib/gitlab/import_export/command_line_util.rb b/lib/gitlab/import_export/command_line_util.rb
index 1140e7beb9a..9fc83afc4f7 100644
--- a/lib/gitlab/import_export/command_line_util.rb
+++ b/lib/gitlab/import_export/command_line_util.rb
@@ -24,7 +24,7 @@ module Gitlab
       end
 
       def tar_with_options(archive:, dir:, options:)
-        cmd = %W(tar -#{options} #{archive} #{dir})
+        cmd = %W(tar -#{options} #{archive} -C #{dir} .)
         _output, status = Gitlab::Popen.popen(cmd)
         status.zero?
       end
diff --git a/lib/gitlab/import_export/saver.rb b/lib/gitlab/import_export/saver.rb
index f87e0fdc7ea..634e58e6039 100644
--- a/lib/gitlab/import_export/saver.rb
+++ b/lib/gitlab/import_export/saver.rb
@@ -14,6 +14,7 @@ module Gitlab
       def save
         if compress_and_save
           remove_storage_path
+          Rails.logger.info("Saved project export #{archive_file}")
           archive_file
         else
           false
-- 
GitLab