Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
4e1c413e
Commit
4e1c413e
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move tilde expnasion to util.
parent
3b241486
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
12 deletions
+28
-12
config/config.go
config/config.go
+12
-12
util/util.go
util/util.go
+16
-0
No files found.
config/config.go
View file @
4e1c413e
...
...
@@ -2,8 +2,7 @@ package config
import
(
"os"
"os/user"
"strings"
u
"github.com/jbenet/go-ipfs/util"
)
type
Identity
struct
{
...
...
@@ -35,15 +34,10 @@ func LoadConfig(filename string) (*Config, error) {
filename
=
defaultConfigFilePath
}
// expand ~/
if
strings
.
HasPrefix
(
filename
,
"~/"
)
{
usr
,
err
:=
user
.
Current
()
if
err
!=
nil
{
return
nil
,
err
}
dir
:=
usr
.
HomeDir
+
"/"
filename
=
strings
.
Replace
(
filename
,
"~/"
,
dir
,
1
)
// tilde expansion on config file
filename
,
err
:=
u
.
TildeExpansion
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
// if nothing is there, write first conifg file.
...
...
@@ -52,7 +46,13 @@ func LoadConfig(filename string) (*Config, error) {
}
var
cfg
Config
err
:=
ReadConfigFile
(
filename
,
&
cfg
)
err
=
ReadConfigFile
(
filename
,
&
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
// tilde expansion on datastore path
cfg
.
Datastore
.
Path
,
err
=
u
.
TildeExpansion
(
cfg
.
Datastore
.
Path
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
util/util.go
View file @
4e1c413e
...
...
@@ -4,6 +4,8 @@ import (
"fmt"
mh
"github.com/jbenet/go-multihash"
"os"
"os/user"
"strings"
)
var
Debug
bool
...
...
@@ -17,6 +19,20 @@ func Hash(data []byte) (mh.Multihash, error) {
return
mh
.
Sum
(
data
,
mh
.
SHA2_256
,
-
1
)
}
// tilde expansion
func
TildeExpansion
(
filename
string
)
(
string
,
error
)
{
if
strings
.
HasPrefix
(
filename
,
"~/"
)
{
usr
,
err
:=
user
.
Current
()
if
err
!=
nil
{
return
""
,
err
}
dir
:=
usr
.
HomeDir
+
"/"
filename
=
strings
.
Replace
(
filename
,
"~/"
,
dir
,
1
)
}
return
filename
,
nil
}
// Shorthand printing functions.
func
PErr
(
format
string
,
a
...
interface
{})
{
fmt
.
Fprintf
(
os
.
Stderr
,
format
,
a
...
)
...
...
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