summaryrefslogtreecommitdiff
path: root/lib/gitlab/satellite/files/file_action.rb
blob: 6446b14568a5de087d3e0cbbf91506dacf24fa74 (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
module Gitlab
  module Satellite
    class FileAction < Action
      attr_accessor :file_path, :ref

      def initialize(user, project, ref, file_path)
        super user, project
        @file_path = file_path
        @ref = ref
      end

      def safe_path?(path)
        File.absolute_path(path) == path
      end

      def write_file(abs_file_path, content, file_encoding = 'text')
        if file_encoding == 'base64'
          File.open(abs_file_path, 'wb') { |f| f.write(Base64.decode64(content)) }
        else
          File.open(abs_file_path, 'w') { |f| f.write(content) }
        end
      end
    end
  end
end