2013-11-05 03:28:49 -05:00
|
|
|
module Gitlab
|
|
|
|
module Satellite
|
|
|
|
class FileAction < Action
|
|
|
|
attr_accessor :file_path, :ref
|
|
|
|
|
|
|
|
def initialize(user, project, ref, file_path)
|
2014-06-11 16:37:21 -04:00
|
|
|
super user, project
|
2013-11-05 03:28:49 -05:00
|
|
|
@file_path = file_path
|
|
|
|
@ref = ref
|
|
|
|
end
|
2013-11-20 03:21:45 -05:00
|
|
|
|
|
|
|
def safe_path?(path)
|
|
|
|
File.absolute_path(path) == path
|
|
|
|
end
|
2014-01-16 11:02:09 -05:00
|
|
|
|
|
|
|
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
|
2013-11-05 03:28:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|