kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.4 KiB
110 lines
3.4 KiB
9 years ago
|
#-- encoding: UTF-8
|
||
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
9 years ago
|
##
|
||
|
# Provides an asynchronous job to create a managed repository on the filesystem.
|
||
|
# Currently, this is run synchronously due to potential issues
|
||
|
# with error handling.
|
||
|
# We envision a repository management wrapper that covers transactional
|
||
|
# creation and deletion of repositories BOTH on the database and filesystem.
|
||
|
# Until then, a synchronous process is more failsafe.
|
||
9 years ago
|
class Scm::CreateLocalRepositoryJob
|
||
9 years ago
|
include OpenProject::BeforeDelayedJob
|
||
9 years ago
|
|
||
9 years ago
|
def initialize(repository)
|
||
9 years ago
|
# Cowardly refusing to override existing local repository
|
||
|
if File.directory?(repository.root_url)
|
||
|
raise OpenProject::Scm::Exceptions::ScmError.new(
|
||
|
I18n.t('repositories.errors.exists_on_filesystem')
|
||
|
)
|
||
|
end
|
||
|
|
||
9 years ago
|
# TODO currently uses the full repository object,
|
||
|
# as the Job is performed synchronously.
|
||
|
# Change this to serialize the ID once its turned to process asynchronously.
|
||
9 years ago
|
@repository = repository
|
||
9 years ago
|
end
|
||
|
|
||
|
def perform
|
||
|
# Create the repository locally.
|
||
9 years ago
|
mode = (config[:mode] || default_mode)
|
||
|
|
||
|
# Ensure that chmod receives an octal number
|
||
|
unless mode.is_a? Integer
|
||
|
mode = mode.to_i(8)
|
||
|
end
|
||
|
|
||
9 years ago
|
create(mode)
|
||
|
|
||
|
# Allow adapter to act upon the created repository
|
||
|
# e.g., initializing an empty scm repository within it
|
||
|
repository.managed_repo_created
|
||
|
|
||
9 years ago
|
# Ensure group ownership after creation
|
||
|
ensure_group(mode, config[:group])
|
||
9 years ago
|
end
|
||
|
|
||
|
def destroy_failed_jobs?
|
||
|
true
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
##
|
||
9 years ago
|
# Creates the repository at the +root_url+.
|
||
9 years ago
|
# Accepts an overriden permission mode mask from the scm config,
|
||
|
# or sets a sensible default of 0700.
|
||
|
def create(mode)
|
||
9 years ago
|
FileUtils.mkdir_p(repository.root_url, mode: mode)
|
||
9 years ago
|
end
|
||
|
|
||
|
##
|
||
9 years ago
|
# Overrides the group permission of the created repository
|
||
9 years ago
|
# after the adapter was able to work in the directory.
|
||
9 years ago
|
def ensure_group(mode, group)
|
||
9 years ago
|
FileUtils.chmod_R(mode, repository.root_url)
|
||
9 years ago
|
|
||
9 years ago
|
# Note that this is effectively a noop when group is nil,
|
||
9 years ago
|
# and then permissions remain OPs runuser/-group
|
||
9 years ago
|
FileUtils.chown_R(nil, group, repository.root_url)
|
||
9 years ago
|
end
|
||
|
|
||
|
def config
|
||
9 years ago
|
@config ||= repository.class.scm_config
|
||
9 years ago
|
end
|
||
|
|
||
|
def repository
|
||
9 years ago
|
@repository
|
||
9 years ago
|
end
|
||
|
|
||
|
def default_mode
|
||
|
0700
|
||
|
end
|
||
|
end
|