37
def service_control(command, args={})
38
args = args.collect do |key, value|
39
"#{key}= #{Svnserve.escape_value(value)}"
41
result = `sc #{command} #{service_name} #{args}`
42
if result.match(/FAILED/)
43
raise "Failed to #{command} #{service_name}: #{args}"
45
/^\s*STATE\s*:\s\d+\s*(.*?)\s*$/ =~ result
49
def grant_everyone_full_access(dir)
50
dir = dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)
51
`cacls #{Svnserve.escape_value(dir)} /T /E /P Everyone:F`
56
service_control("query")
64
"STOPPED" == service_control("query") rescue true
68
38
@svnserve_port = @svnserve_ports.last
69
39
@repos_svnserve_uri = "svn://#{@svnserve_host}:#{@svnserve_port}"
70
grant_everyone_full_access(@full_repos_path)
72
41
@@service_created ||= begin
73
42
@@service_created = true
74
service_control('stop') unless service_stopped?
75
service_control('delete') if service_exists?
77
svnserve_dir = File.expand_path("svnserve")
78
FileUtils.mkdir_p(svnserve_dir)
80
service_control('stop') unless service_stopped?
81
service_control('delete') if service_exists?
82
FileUtils.rm_rf(svnserve_dir)
85
service_control('stop') unless service_stopped?
86
service_control('delete') if service_exists?
87
FileUtils.rm_rf(svnserve_dir)
90
config = SetupEnvironment.gen_make_opts
91
apr_version_include = Pathname.new(config["--with-apr"]) +
92
'include' + 'apr_version.h'
93
%r'^\s*#define\s+APR_MAJOR_VERSION\s+(\d+)' =~ apr_version_include.read
94
apr_major_version = $1 == '0' ? '' : "-#{$1}"
97
targets = %W(svnserve.exe libsvn_subr-1.dll libsvn_repos-1.dll
98
libsvn_fs-1.dll libsvn_delta-1.dll
99
libaprutil#{apr_major_version}.dll
100
libapr#{apr_major_version}.dll
101
libapriconv#{apr_major_version}.dll
102
libdb??.dll libdb??d.dll)
103
ENV["PATH"].split(";").each do |path|
105
# Change the cwd to path, but ignore non-existent paths.
113
targets.each do |target|
114
matching_paths = Dir.glob(target)
115
matching_paths.each do |target_path|
116
target_path = File.join(path.tr('\\', '/'), target_path)
117
if File.exists?(target_path)
118
found_targets << target
121
FileUtils.cp(target_path, svnserve_dir)
123
# On Windows the tests frequently fail spuriously with a
124
# 'Errno::EACCES: Permission denied - svnserve.exe' error.
125
# Sleeping for a few seconds avoids this.
139
targets -= found_targets
140
break if targets.empty?
143
# Remove optional targets instead of raising below. If they are really
144
# needed, svnserve won't start anyway.
145
targets -= %W[libapriconv#{apr_major_version}.dll]
146
# Ditto these four, since svnserve.exe might be a static build.
147
targets -= %W[libsvn_subr-1.dll]
148
targets -= %W[libsvn_repos-1.dll]
149
targets -= %W[libsvn_fs-1.dll]
150
targets -= %W[libsvn_delta-1.dll]
152
unless targets.empty?
153
raise "can't find libraries to work svnserve: #{targets.join(' ')}"
156
grant_everyone_full_access(svnserve_dir)
158
svnserve_path = File.join(svnserve_dir, "svnserve.exe")
159
svnserve_path = svnserve_path.tr(File::SEPARATOR,
44
top_directory = File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..")
45
build_type = ENV["BUILD_TYPE"] || "Release"
46
svnserve_path = File.join(top_directory, build_type, 'subversion', 'svnserve', 'svnserve.exe')
161
47
svnserve_path = Svnserve.escape_value(svnserve_path)
163
49
root = @full_repos_path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
50
FileUtils.mkdir_p(root)
165
args = ["--service", "--root", Svnserve.escape_value(root),
166
"--listen-host", @svnserve_host,
167
"--listen-port", @svnserve_port]
52
IO.popen("#{svnserve_path} -d -r #{Svnserve.escape_value(root)} --listen-host #{@svnserve_host} --listen-port #{@svnserve_port} --pid-file #{@svnserve_pid_file}")
168
53
user = ENV["USERNAME"] || Etc.getlogin
169
service_control('create',
170
[["binPath", "#{svnserve_path} #{args.join(' ')}"],
171
["DisplayName", service_name],
55
# Give svnserve a bit of time to start
174
service_control('start')
178
61
def teardown_svnserve
179
service_control('stop') unless service_stopped?
63
# Load @svnserve_pid_file
182
67
def add_pre_revprop_change_hook