summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/wiki_repo_saver.rb
blob: 5fa2e101e29506834ae3aa6c53c98682658a9838 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Gitlab
  module ImportExport
    class WikiRepoSaver < RepoSaver
      def save
        @wiki = ProjectWiki.new(@project)
        return true unless wiki_repository_exists? # it's okay to have no Wiki

        bundle_to_disk(File.join(@shared.export_path, project_filename))
      end

      def bundle_to_disk(full_path)
        mkdir_p(@shared.export_path)
        @wiki.repository.bundle_to_disk(full_path)
      rescue => e
        @shared.error(e)
        false
      end

      private

      def project_filename
        "project.wiki.bundle"
      end

      def path_to_repo
        @wiki.repository.path_to_repo
      end

      def wiki_repository_exists?
        File.exist?(@wiki.repository.path_to_repo) && !@wiki.repository.empty?
      end
    end
  end
end