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
02377fab
Commit
02377fab
authored
Jul 03, 2015
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
assets: remove seed logic from init
License: MIT Signed-off-by:
Henry
<
cryptix@riseup.net
>
parent
5fbf1e74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
38 deletions
+59
-38
assets/assets.go
assets/assets.go
+57
-7
cmd/ipfs/init.go
cmd/ipfs/init.go
+2
-31
No files found.
assets/assets.go
View file @
02377fab
...
...
@@ -2,11 +2,61 @@
package
assets
var
InitDir
=
map
[
string
][]
byte
{
"about"
:
MustAsset
(
"init-doc/about"
),
"readme"
:
MustAsset
(
"init-doc/readme"
),
"help"
:
MustAsset
(
"init-doc/help"
),
"contact"
:
MustAsset
(
"init-doc/contact"
),
"security-notes"
:
MustAsset
(
"init-doc/security-notes"
),
"quick-start"
:
MustAsset
(
"init-doc/quick-start"
),
import
(
"bytes"
"fmt"
"path/filepath"
"github.com/ipfs/go-ipfs/blocks/key"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
)
// initDocPaths lists the paths for the docs we want to seed during --init
var
initDocPaths
=
[]
string
{
"init-doc/about"
,
"init-doc/readme"
,
"init-doc/help"
,
"init-doc/contact"
,
"init-doc/security-notes"
,
"init-doc/quick-start"
,
}
func
SeedInitDocs
(
nd
*
core
.
IpfsNode
)
(
*
key
.
Key
,
error
)
{
dirb
:=
uio
.
NewDirectory
(
nd
.
DAG
)
for
_
,
p
:=
range
initDocPaths
{
d
,
err
:=
Asset
(
p
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"assets.AddDocuDir: could load Asset '%s': %s"
,
p
,
err
)
}
s
,
err
:=
coreunix
.
Add
(
nd
,
bytes
.
NewBuffer
(
d
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"assets.AddDocuDir: could not Add '%s': %s"
,
p
,
err
)
}
fname
:=
filepath
.
Base
(
p
)
k
:=
key
.
B58KeyDecode
(
s
)
if
err
:=
dirb
.
AddChild
(
fname
,
k
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"assets.AddDocuDir: could not add '%s' as a child: %s"
,
fname
,
err
)
}
}
dir
:=
dirb
.
GetNode
()
dkey
,
err
:=
nd
.
DAG
.
Add
(
dir
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"assets.AddDocuDir: DAG.Add(dir) failed: %s"
,
err
)
}
if
err
:=
nd
.
Pinning
.
Pin
(
nd
.
Context
(),
dir
,
true
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"assets.AddDocuDir: Pinning on init-docu failed: %s"
,
err
)
}
if
err
:=
nd
.
Pinning
.
Flush
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"assets.AddDocuDir: Pinnig flush failed: %s"
,
err
)
}
return
&
dkey
,
nil
}
cmd/ipfs/init.go
View file @
02377fab
package
main
import
(
"bytes"
"errors"
"fmt"
"io"
...
...
@@ -10,14 +9,11 @@ import (
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
assets
"github.com/ipfs/go-ipfs/assets"
key
"github.com/ipfs/go-ipfs/blocks/key"
cmds
"github.com/ipfs/go-ipfs/commands"
core
"github.com/ipfs/go-ipfs/core"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
namesys
"github.com/ipfs/go-ipfs/namesys"
config
"github.com/ipfs/go-ipfs/repo/config"
fsrepo
"github.com/ipfs/go-ipfs/repo/fsrepo"
uio
"github.com/ipfs/go-ipfs/unixfs/io"
)
const
nBitsForKeypairDefault
=
2048
...
...
@@ -167,34 +163,9 @@ func addDefaultAssets(out io.Writer, repoRoot string) error {
}
defer
nd
.
Close
()
dirb
:=
uio
.
NewDirectory
(
nd
.
DAG
)
// add every file in the assets pkg
for
fname
,
file
:=
range
assets
.
InitDir
{
buf
:=
bytes
.
NewBuffer
(
file
)
s
,
err
:=
coreunix
.
Add
(
nd
,
buf
)
if
err
!=
nil
{
return
err
}
k
:=
key
.
B58KeyDecode
(
s
)
if
err
:=
dirb
.
AddChild
(
fname
,
k
);
err
!=
nil
{
return
err
}
}
dir
:=
dirb
.
GetNode
()
dkey
,
err
:=
nd
.
DAG
.
Add
(
dir
)
dkey
,
err
:=
assets
.
SeedInitDocs
(
nd
)
if
err
!=
nil
{
return
err
}
if
err
:=
nd
.
Pinning
.
Pin
(
ctx
,
dir
,
true
);
err
!=
nil
{
return
err
}
if
err
:=
nd
.
Pinning
.
Flush
();
err
!=
nil
{
return
err
return
fmt
.
Errorf
(
"init: seeding init docs failed: %s"
,
err
)
}
if
_
,
err
=
fmt
.
Fprintf
(
out
,
"to get started, enter:
\n
"
);
err
!=
nil
{
...
...
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