Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
63d0c0b9
Commit
63d0c0b9
authored
Feb 26, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gitlab_popen_array' into 'master'
Change Gitlab::Popen to only accept arrays as commands
parents
6c1af645
36c2c354
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
7 deletions
+31
-7
app/models/key.rb
app/models/key.rb
+1
-1
lib/gitlab/popen.rb
lib/gitlab/popen.rb
+11
-3
lib/gitlab/satellite/satellite.rb
lib/gitlab/satellite/satellite.rb
+1
-1
spec/lib/gitlab/popen_spec.rb
spec/lib/gitlab/popen_spec.rb
+18
-2
No files found.
app/models/key.rb
View file @
63d0c0b9
...
...
@@ -53,7 +53,7 @@ class Key < ActiveRecord::Base
Tempfile
.
open
(
'gitlab_key_file'
)
do
|
file
|
file
.
puts
key
file
.
rewind
cmd_output
,
cmd_status
=
popen
(
"ssh-keygen -lf
#{
file
.
path
}
"
,
'/tmp'
)
cmd_output
,
cmd_status
=
popen
(
%W(ssh-keygen -lf
#{
file
.
path
}
)
,
'/tmp'
)
end
if
cmd_status
.
zero?
...
...
lib/gitlab/popen.rb
View file @
63d0c0b9
require
'fileutils'
require
'open3'
module
Gitlab
module
Popen
def
popen
(
cmd
,
path
)
extend
self
def
popen
(
cmd
,
path
=
nil
)
unless
cmd
.
is_a?
(
Array
)
raise
"System commands must be given as an array of strings"
end
path
||=
Dir
.
pwd
vars
=
{
"PWD"
=>
path
}
options
=
{
chdir:
path
}
...
...
@@ -12,10 +20,10 @@ module Gitlab
@cmd_output
=
""
@cmd_status
=
0
Open3
.
popen3
(
vars
,
cmd
,
options
)
do
|
stdin
,
stdout
,
stderr
,
wait_thr
|
@cmd_status
=
wait_thr
.
value
.
exitstatus
Open3
.
popen3
(
vars
,
*
cmd
,
options
)
do
|
stdin
,
stdout
,
stderr
,
wait_thr
|
@cmd_output
<<
stdout
.
read
@cmd_output
<<
stderr
.
read
@cmd_status
=
wait_thr
.
value
.
exitstatus
end
return
@cmd_output
,
@cmd_status
...
...
lib/gitlab/satellite/satellite.rb
View file @
63d0c0b9
...
...
@@ -33,7 +33,7 @@ module Gitlab
end
def
create
output
,
status
=
popen
(
"git clone
#{
project
.
repository
.
path_to_repo
}
#{
path
}
"
,
output
,
status
=
popen
(
%W(git clone --
#{
project
.
repository
.
path_to_repo
}
#{
path
}
)
,
Gitlab
.
config
.
satellites
.
path
)
log
(
"PID:
#{
project
.
id
}
: git clone
#{
project
.
repository
.
path_to_repo
}
#{
path
}
"
)
...
...
spec/lib/gitlab/popen_spec.rb
View file @
63d0c0b9
...
...
@@ -10,7 +10,7 @@ describe 'Gitlab::Popen', no_db: true do
context
'zero status'
do
before
do
@output
,
@status
=
@klass
.
new
.
popen
(
'ls'
,
path
)
@output
,
@status
=
@klass
.
new
.
popen
(
%W(ls)
,
path
)
end
it
{
@status
.
should
be_zero
}
...
...
@@ -19,11 +19,27 @@ describe 'Gitlab::Popen', no_db: true do
context
'non-zero status'
do
before
do
@output
,
@status
=
@klass
.
new
.
popen
(
'cat NOTHING'
,
path
)
@output
,
@status
=
@klass
.
new
.
popen
(
%W(cat NOTHING)
,
path
)
end
it
{
@status
.
should
==
1
}
it
{
@output
.
should
include
(
'No such file or directory'
)
}
end
context
'unsafe string command'
do
it
'raises an error when it gets called with a string argument'
do
expect
{
@klass
.
new
.
popen
(
'ls'
,
path
)
}.
to
raise_error
end
end
context
'without a directory argument'
do
before
do
@output
,
@status
=
@klass
.
new
.
popen
(
%W(ls)
)
end
it
{
@status
.
should
be_zero
}
it
{
@output
.
should
include
(
'spec'
)
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment