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-dms3
Commits
fa4cfe8d
Commit
fa4cfe8d
authored
10 years ago
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(init, fsrepo): go through repo to write to config
parent
a2d1e339
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
6 deletions
+45
-6
cmd/ipfs/init.go
cmd/ipfs/init.go
+8
-6
repo/fsrepo/fsrepo.go
repo/fsrepo/fsrepo.go
+37
-0
No files found.
cmd/ipfs/init.go
View file @
fa4cfe8d
...
...
@@ -95,11 +95,6 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
u
.
POut
(
"initializing ipfs node at %s
\n
"
,
configRoot
)
configFilename
,
err
:=
config
.
Filename
(
configRoot
)
if
err
!=
nil
{
return
nil
,
debugerror
.
New
(
"Couldn't get home directory path"
)
}
if
fsrepo
.
ConfigIsInitialized
(
configRoot
)
&&
!
force
{
return
nil
,
errCannotInitConfigExists
}
...
...
@@ -109,7 +104,14 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
return
nil
,
err
}
if
err
:=
config
.
WriteConfigFile
(
configFilename
,
conf
);
err
!=
nil
{
repo
:=
fsrepo
.
At
(
configRoot
)
if
err
:=
repo
.
Open
();
err
!=
nil
{
return
nil
,
err
}
if
err
:=
repo
.
SetConfig
(
conf
);
err
!=
nil
{
return
nil
,
err
}
if
err
:=
repo
.
Close
();
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
repo/fsrepo/fsrepo.go
View file @
fa4cfe8d
package
fsrepo
import
(
"io"
config
"github.com/jbenet/go-ipfs/repo/config"
util
"github.com/jbenet/go-ipfs/util"
)
type
FSRepo
struct
{
path
string
config
config
.
Config
}
func
At
(
path
string
)
*
FSRepo
{
return
&
FSRepo
{
path
:
path
,
}
}
func
(
r
*
FSRepo
)
Open
()
error
{
// TODO may need to check that directory is writeable
// TODO acquire repo lock
return
nil
}
func
(
r
*
FSRepo
)
SetConfig
(
conf
*
config
.
Config
)
error
{
configFilename
,
err
:=
config
.
Filename
(
r
.
path
)
if
err
!=
nil
{
return
err
}
if
err
:=
config
.
WriteConfigFile
(
configFilename
,
conf
);
err
!=
nil
{
return
err
}
r
.
config
=
*
conf
// copy so caller cannot modify the private config
return
nil
}
func
(
r
*
FSRepo
)
Close
()
error
{
return
nil
// TODO release repo lock
}
var
_
io
.
Closer
=
&
FSRepo
{}
// ConfigIsInitialized returns true if the config exists in provided |path|.
func
ConfigIsInitialized
(
path
string
)
bool
{
configFilename
,
err
:=
config
.
Filename
(
path
)
...
...
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