debian-mirror-gitlab/app/services/files/create_service.rb

38 lines
1.1 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require_relative "base_service"
module Files
2015-09-25 12:07:36 +05:30
class CreateService < Files::BaseService
def commit
2016-09-29 09:46:39 +05:30
repository.commit_file(current_user, @file_path, @file_content, @commit_message, @target_branch, false, author_email: @author_email, author_name: @author_name)
2015-09-25 12:07:36 +05:30
end
2014-09-02 18:07:02 +05:30
2015-09-25 12:07:36 +05:30
def validate
super
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
if @file_path =~ Gitlab::Regex.directory_traversal_regex
raise_error(
'Your changes could not be committed, because the file name ' +
Gitlab::Regex.directory_traversal_regex_message
)
end
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
unless @file_path =~ Gitlab::Regex.file_path_regex
2015-09-25 12:07:36 +05:30
raise_error(
2014-09-02 18:07:02 +05:30
'Your changes could not be committed, because the file name ' +
2015-11-26 14:37:03 +05:30
Gitlab::Regex.file_path_regex_message
2014-09-02 18:07:02 +05:30
)
end
2015-09-25 12:07:36 +05:30
unless project.empty_repo?
@file_path.slice!(0) if @file_path.start_with?('/')
2014-09-02 18:07:02 +05:30
blob = repository.blob_at_branch(@source_branch, @file_path)
2015-04-26 12:48:37 +05:30
if blob
2016-08-24 12:49:21 +05:30
raise_error('Your changes could not be committed because a file with the same name already exists')
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
end
end