Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
304764ac
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
304764ac
编写于
4月 08, 2019
作者:
H
hongming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update dependency
Signed-off-by:
N
hongming
<
talonwan@yunify.com
>
上级
c4c021b5
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
637 addition
and
54 deletion
+637
-54
Gopkg.lock
Gopkg.lock
+449
-54
vendor/github.com/mitchellh/go-homedir/LICENSE
vendor/github.com/mitchellh/go-homedir/LICENSE
+21
-0
vendor/github.com/mitchellh/go-homedir/homedir.go
vendor/github.com/mitchellh/go-homedir/homedir.go
+167
-0
未找到文件。
Gopkg.lock
浏览文件 @
304764ac
此差异已折叠。
点击以展开。
vendor/github.com/mitchellh/go-homedir/LICENSE
0 → 100644
浏览文件 @
304764ac
The MIT License (MIT)
Copyright (c) 2013 Mitchell Hashimoto
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
vendor/github.com/mitchellh/go-homedir/homedir.go
0 → 100644
浏览文件 @
304764ac
package
homedir
import
(
"bytes"
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
)
// DisableCache will disable caching of the home directory. Caching is enabled
// by default.
var
DisableCache
bool
var
homedirCache
string
var
cacheLock
sync
.
RWMutex
// Dir returns the home directory for the executing user.
//
// This uses an OS-specific method for discovering the home directory.
// An error is returned if a home directory cannot be detected.
func
Dir
()
(
string
,
error
)
{
if
!
DisableCache
{
cacheLock
.
RLock
()
cached
:=
homedirCache
cacheLock
.
RUnlock
()
if
cached
!=
""
{
return
cached
,
nil
}
}
cacheLock
.
Lock
()
defer
cacheLock
.
Unlock
()
var
result
string
var
err
error
if
runtime
.
GOOS
==
"windows"
{
result
,
err
=
dirWindows
()
}
else
{
// Unix-like system, so just assume Unix
result
,
err
=
dirUnix
()
}
if
err
!=
nil
{
return
""
,
err
}
homedirCache
=
result
return
result
,
nil
}
// Expand expands the path to include the home directory if the path
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
// returned as-is.
func
Expand
(
path
string
)
(
string
,
error
)
{
if
len
(
path
)
==
0
{
return
path
,
nil
}
if
path
[
0
]
!=
'~'
{
return
path
,
nil
}
if
len
(
path
)
>
1
&&
path
[
1
]
!=
'/'
&&
path
[
1
]
!=
'\\'
{
return
""
,
errors
.
New
(
"cannot expand user-specific home dir"
)
}
dir
,
err
:=
Dir
()
if
err
!=
nil
{
return
""
,
err
}
return
filepath
.
Join
(
dir
,
path
[
1
:
]),
nil
}
// Reset clears the cache, forcing the next call to Dir to re-detect
// the home directory. This generally never has to be called, but can be
// useful in tests if you're modifying the home directory via the HOME
// env var or something.
func
Reset
()
{
cacheLock
.
Lock
()
defer
cacheLock
.
Unlock
()
homedirCache
=
""
}
func
dirUnix
()
(
string
,
error
)
{
homeEnv
:=
"HOME"
if
runtime
.
GOOS
==
"plan9"
{
// On plan9, env vars are lowercase.
homeEnv
=
"home"
}
// First prefer the HOME environmental variable
if
home
:=
os
.
Getenv
(
homeEnv
);
home
!=
""
{
return
home
,
nil
}
var
stdout
bytes
.
Buffer
// If that fails, try OS specific commands
if
runtime
.
GOOS
==
"darwin"
{
cmd
:=
exec
.
Command
(
"sh"
,
"-c"
,
`dscl -q . -read /Users/"$(whoami)" NFSHomeDirectory | sed 's/^[^ ]*: //'`
)
cmd
.
Stdout
=
&
stdout
if
err
:=
cmd
.
Run
();
err
==
nil
{
result
:=
strings
.
TrimSpace
(
stdout
.
String
())
if
result
!=
""
{
return
result
,
nil
}
}
}
else
{
cmd
:=
exec
.
Command
(
"getent"
,
"passwd"
,
strconv
.
Itoa
(
os
.
Getuid
()))
cmd
.
Stdout
=
&
stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
// If the error is ErrNotFound, we ignore it. Otherwise, return it.
if
err
!=
exec
.
ErrNotFound
{
return
""
,
err
}
}
else
{
if
passwd
:=
strings
.
TrimSpace
(
stdout
.
String
());
passwd
!=
""
{
// username:password:uid:gid:gecos:home:shell
passwdParts
:=
strings
.
SplitN
(
passwd
,
":"
,
7
)
if
len
(
passwdParts
)
>
5
{
return
passwdParts
[
5
],
nil
}
}
}
}
// If all else fails, try the shell
stdout
.
Reset
()
cmd
:=
exec
.
Command
(
"sh"
,
"-c"
,
"cd && pwd"
)
cmd
.
Stdout
=
&
stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
""
,
err
}
result
:=
strings
.
TrimSpace
(
stdout
.
String
())
if
result
==
""
{
return
""
,
errors
.
New
(
"blank output when reading home directory"
)
}
return
result
,
nil
}
func
dirWindows
()
(
string
,
error
)
{
// First prefer the HOME environmental variable
if
home
:=
os
.
Getenv
(
"HOME"
);
home
!=
""
{
return
home
,
nil
}
// Prefer standard environment variable USERPROFILE
if
home
:=
os
.
Getenv
(
"USERPROFILE"
);
home
!=
""
{
return
home
,
nil
}
drive
:=
os
.
Getenv
(
"HOMEDRIVE"
)
path
:=
os
.
Getenv
(
"HOMEPATH"
)
home
:=
drive
+
path
if
drive
==
""
||
path
==
""
{
return
""
,
errors
.
New
(
"HOMEDRIVE, HOMEPATH, or USERPROFILE are blank"
)
}
return
home
,
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录