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
Léo-Paul Géneau
gitlab-ce
Commits
0432bdf1
Commit
0432bdf1
authored
10 years ago
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change Gitlab::Popen to use arrays for commands
parent
9f20580e
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
lib/gitlab/popen.rb
lib/gitlab/popen.rb
+7
-2
spec/lib/gitlab/popen_spec.rb
spec/lib/gitlab/popen_spec.rb
+9
-2
No files found.
lib/gitlab/popen.rb
View file @
0432bdf1
require
'fileutils'
require
'open3'
module
Gitlab
module
Popen
def
popen
(
cmd
,
path
)
unless
cmd
.
is_a?
(
Array
)
raise
"System commands must be given as an array of strings"
end
vars
=
{
"PWD"
=>
path
}
options
=
{
chdir:
path
}
...
...
@@ -12,10 +17,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
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/popen_spec.rb
View file @
0432bdf1
...
...
@@ -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,18 @@ 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
end
This diff is collapsed.
Click to expand it.
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