Cross Reference: symlinks.rb
xref
: /
ontohub
/
app
/
models
/
repository
/
symlinks.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
symlinks.rb revision 98ff97ecba1886772d1380e4b01ebe5f1dccac9f
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
#
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
# Generates a symlink for exposing the repositories via git daemon
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
#
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
module
Repository
::
Symlinks
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
extend
ActiveSupport
::
Concern
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
included
do
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
after_save
:
symlinks_update
,
if
: :
path_changed
?
97af921a43ee62e760f2ea3cfafb6a2bea0414fb
Eugen Kuksa
before_destroy
:
symlinks_remove
end
SUPPORTED_LINK_CATEGORIES
= %i
(
git_daemon
git_ssh
)
def
symlink_path
(
category
)
unless
SUPPORTED_LINK_CATEGORIES.include
?
(
category
)
raise
"Unsupported symlink category: #{
category.inspect
}"
end
Ontohub
::
Application.config.send
(:
"#{category}_path"
)
.
join
(
"#{path}.git"
)
end
protected
def
create_hooks_symlink
hooks_symlink_name
=
local_path.join
(
"hooks"
)
hooks_symlink_name.rmtree
hooks_symlink_name
.
make_symlink
(
cleanup_release
(
Rails.root.join
(
'git'
,
'hooks'
)
)
)
end
def
symlinks_update
create_cloning_symlink
(:
git_daemon
)
if
public_r
? ||
public_rw
?
create_cloning_symlink
(:
git_ssh
)
end
def
symlinks_remove
SUPPORTED_LINK_CATEGORIES.each
do
|
category
|
remove_cloning_symlink
(
category
)
end
end
def
create_cloning_symlink
(
category
)
symlink_path
(
category
)
.
join
(
'..'
)
.
mkpath
remove_cloning_symlink
(
category
)
symlink_path
(
category
)
.
make_symlink
(
cleanup_release
(
local_path
)
)
end
def
remove_cloning_symlink
(
category
)
symlink_path
(
category
)
.
unlink
if
symlink_path
(
category
)
.
exist
?
end
# Replace capistrano-style release with 'current'-symlink.
def
cleanup_release
(
path
)
PathsInitializer.cleanup
_release
(
path
)
end
end