Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
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
nexedi
gitlab-shell
Commits
f6a7f171
Commit
f6a7f171
authored
Apr 09, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly determine the root directory for gitlab-shell
Credit to
https://gitlab.com/ejiek
for spotting this one.
parent
1b741a0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
11 deletions
+24
-11
go/cmd/gitlab-shell/main.go
go/cmd/gitlab-shell/main.go
+24
-11
No files found.
go/cmd/gitlab-shell/main.go
View file @
f6a7f171
...
...
@@ -11,21 +11,22 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/go/internal/config"
)
var
(
binDir
string
rootDir
string
readWriter
*
readwriter
.
ReadWriter
)
// findRootDir determines the root directory (and so, the location of the config
// file) from os.Executable()
func
findRootDir
()
(
string
,
error
)
{
path
,
err
:=
os
.
Executable
()
if
err
!=
nil
{
return
""
,
err
}
func
init
()
{
binDir
=
filepath
.
Dir
(
os
.
Args
[
0
])
rootDir
=
filepath
.
Dir
(
binDir
)
readWriter
=
&
readwriter
.
ReadWriter
{
Out
:
os
.
Stdout
,
In
:
os
.
Stdin
,
ErrOut
:
os
.
Stderr
}
// Start: /opt/.../gitlab-shell/bin/gitlab-shell
// Ends: /opt/.../gitlab-shell
return
filepath
.
Dir
(
filepath
.
Dir
(
path
)),
nil
}
// rubyExec will never return. It either replaces the current process with a
// Ruby interpreter, or outputs an error and kills the process.
func
execRuby
()
{
func
execRuby
(
readWriter
*
readwriter
.
ReadWriter
)
{
cmd
:=
&
fallback
.
Command
{}
if
err
:=
cmd
.
Execute
(
readWriter
);
err
!=
nil
{
fmt
.
Fprintf
(
readWriter
.
ErrOut
,
"Failed to exec: %v
\n
"
,
err
)
...
...
@@ -34,12 +35,24 @@ func execRuby() {
}
func
main
()
{
readWriter
:=
&
readwriter
.
ReadWriter
{
Out
:
os
.
Stdout
,
In
:
os
.
Stdin
,
ErrOut
:
os
.
Stderr
,
}
rootDir
,
err
:=
findRootDir
()
if
err
!=
nil
{
fmt
.
Fprintln
(
readWriter
.
ErrOut
,
"Failed to determine root directory, falling back to gitlab-shell-ruby"
)
execRuby
(
readWriter
)
}
// Fall back to Ruby in case of problems reading the config, but issue a
// warning as this isn't something we can sustain indefinitely
config
,
err
:=
config
.
NewFromDir
(
rootDir
)
if
err
!=
nil
{
fmt
.
Fprintln
(
readWriter
.
ErrOut
,
"Failed to read config, falling back to gitlab-shell-ruby"
)
execRuby
()
execRuby
(
readWriter
)
}
cmd
,
err
:=
command
.
New
(
os
.
Args
,
config
)
...
...
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