Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
062f47ef
Unverified
提交
062f47ef
authored
1月 24, 2019
作者:
Steven Allen
提交者:
GitHub
1月 24, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5938 from ipfs/misc/cleanup-coreunix
Drop some coreunix code
上级
aefb3725
a49c07a1
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
123 行增加
和
231 行删除
+123
-231
assets.go
assets/assets.go
+21
-27
main.go
cmd/ipfswatch/main.go
+22
-2
gateway_test.go
core/corehttp/gateway_test.go
+56
-69
add.go
core/coreunix/add.go
+0
-86
add_test.go
core/coreunix/add_test.go
+0
-20
addcat_test.go
test/integration/addcat_test.go
+8
-9
bench_cat_test.go
test/integration/bench_cat_test.go
+8
-9
three_legged_cat_test.go
test/integration/three_legged_cat_test.go
+8
-9
没有找到文件。
assets/assets.go
浏览文件 @
062f47ef
...
...
@@ -4,15 +4,17 @@
package
assets
import
(
"bytes"
"fmt"
"os"
"path/filepath"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreunix"
"github.com/ipfs/go-ipfs/core/coreapi"
"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
cid
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
uio
"gx/ipfs/QmSMJ4rZbCJaih3y82Ebq7BZqK6vU2FHsKcWKQiE1DPTpS/go-unixfs/io
"
files
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files
"
// this import keeps gx from thinking the dep isn't used
_
"gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV/dir-index-html"
...
...
@@ -45,7 +47,17 @@ func SeedInitDirIndex(nd *core.IpfsNode) (cid.Cid, error) {
}
func
addAssetList
(
nd
*
core
.
IpfsNode
,
l
[]
string
)
(
cid
.
Cid
,
error
)
{
dirb
:=
uio
.
NewDirectory
(
nd
.
DAG
)
api
,
err
:=
coreapi
.
NewCoreAPI
(
nd
)
if
err
!=
nil
{
return
cid
.
Cid
{},
err
}
dirb
,
err
:=
api
.
Object
()
.
New
(
nd
.
Context
(),
options
.
Object
.
Type
(
"unixfs-dir"
))
if
err
!=
nil
{
return
cid
.
Cid
{},
err
}
basePath
:=
iface
.
IpfsPath
(
dirb
.
Cid
())
for
_
,
p
:=
range
l
{
d
,
err
:=
Asset
(
p
)
...
...
@@ -53,40 +65,22 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
return
cid
.
Cid
{},
fmt
.
Errorf
(
"assets: could load Asset '%s': %s"
,
p
,
err
)
}
s
,
err
:=
coreunix
.
Add
(
nd
,
bytes
.
NewBuffer
(
d
))
fp
,
err
:=
api
.
Unixfs
()
.
Add
(
nd
.
Context
(),
files
.
NewBytesFile
(
d
))
if
err
!=
nil
{
return
cid
.
Cid
{},
fmt
.
Errorf
(
"assets: could not Add '%s': %s"
,
p
,
err
)
return
cid
.
Cid
{},
err
}
fname
:=
filepath
.
Base
(
p
)
c
,
err
:=
cid
.
Decode
(
s
)
basePath
,
err
=
api
.
Object
()
.
AddLink
(
nd
.
Context
(),
basePath
,
fname
,
fp
)
if
err
!=
nil
{
return
cid
.
Cid
{},
err
}
node
,
err
:=
nd
.
DAG
.
Get
(
nd
.
Context
(),
c
)
if
err
!=
nil
{
return
cid
.
Cid
{},
err
}
if
err
:=
dirb
.
AddChild
(
nd
.
Context
(),
fname
,
node
);
err
!=
nil
{
return
cid
.
Cid
{},
fmt
.
Errorf
(
"assets: could not add '%s' as a child: %s"
,
fname
,
err
)
}
}
dir
,
err
:=
dirb
.
GetNode
()
if
err
!=
nil
{
if
err
:=
api
.
Pin
()
.
Add
(
nd
.
Context
(),
basePath
);
err
!=
nil
{
return
cid
.
Cid
{},
err
}
if
err
:=
nd
.
Pinning
.
Pin
(
nd
.
Context
(),
dir
,
true
);
err
!=
nil
{
return
cid
.
Cid
{},
fmt
.
Errorf
(
"assets: Pinning on init-docu failed: %s"
,
err
)
}
if
err
:=
nd
.
Pinning
.
Flush
();
err
!=
nil
{
return
cid
.
Cid
{},
fmt
.
Errorf
(
"assets: Pinning flush failed: %s"
,
err
)
}
return
dir
.
Cid
(),
nil
return
basePath
.
Cid
(),
nil
}
cmd/ipfswatch/main.go
浏览文件 @
062f47ef
...
...
@@ -11,11 +11,12 @@ import (
commands
"github.com/ipfs/go-ipfs/commands"
core
"github.com/ipfs/go-ipfs/core"
coreapi
"github.com/ipfs/go-ipfs/core/coreapi"
corehttp
"github.com/ipfs/go-ipfs/core/corehttp"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
fsrepo
"github.com/ipfs/go-ipfs/repo/fsrepo"
process
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
files
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
config
"gx/ipfs/QmcRKBUqc2p3L1ZraoJjbXfs9E6xzvEuyK9iypb5RGwfsr/go-ipfs-config"
homedir
"gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir"
fsnotify
"gx/ipfs/QmfNjggF4Pt6erqg3NDafD3MdvDHk1qqCVr8pL5hnPucS8/fsnotify"
...
...
@@ -83,6 +84,11 @@ func run(ipfsPath, watchPath string) error {
}
defer
node
.
Close
()
api
,
err
:=
coreapi
.
NewCoreAPI
(
node
)
if
err
!=
nil
{
return
err
}
if
*
http
{
addr
:=
"/ip4/127.0.0.1/tcp/5001"
var
opts
=
[]
corehttp
.
ServeOption
{
...
...
@@ -130,9 +136,23 @@ func run(ipfsPath, watchPath string) error {
file
,
err
:=
os
.
Open
(
e
.
Name
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
defer
file
.
Close
()
k
,
err
:=
coreunix
.
Add
(
node
,
file
)
st
,
err
:=
file
.
Stat
()
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
f
,
err
:=
files
.
NewReaderPathFile
(
e
.
Name
,
file
,
st
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
k
,
err
:=
api
.
Unixfs
()
.
Add
(
node
.
Context
(),
f
)
if
err
!=
nil
{
log
.
Println
(
err
)
}
...
...
core/corehttp/gateway_test.go
浏览文件 @
062f47ef
差异被折叠。
点击展开。
core/coreunix/add.go
浏览文件 @
062f47ef
...
...
@@ -7,10 +7,8 @@ import (
"io"
"os"
gopath
"path"
"path/filepath"
"strconv"
"github.com/ipfs/go-ipfs/core"
coreiface
"github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/pin"
...
...
@@ -276,90 +274,6 @@ func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error {
}
}
// Add builds a merkledag node from a reader, adds it to the blockstore,
// and returns the key representing that node.
// If you want to pin it, use NewAdder() and Adder.PinRoot().
func
Add
(
n
*
core
.
IpfsNode
,
r
io
.
Reader
)
(
string
,
error
)
{
return
AddWithContext
(
n
.
Context
(),
n
,
r
)
}
// AddWithContext does the same as Add, but with a custom context.
func
AddWithContext
(
ctx
context
.
Context
,
n
*
core
.
IpfsNode
,
r
io
.
Reader
)
(
string
,
error
)
{
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
fileAdder
,
err
:=
NewAdder
(
ctx
,
n
.
Pinning
,
n
.
Blockstore
,
n
.
DAG
)
if
err
!=
nil
{
return
""
,
err
}
node
,
err
:=
fileAdder
.
add
(
r
)
if
err
!=
nil
{
return
""
,
err
}
return
node
.
Cid
()
.
String
(),
nil
}
// AddR recursively adds files in |path|.
func
AddR
(
n
*
core
.
IpfsNode
,
root
string
)
(
key
string
,
err
error
)
{
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
stat
,
err
:=
os
.
Lstat
(
root
)
if
err
!=
nil
{
return
""
,
err
}
f
,
err
:=
files
.
NewSerialFile
(
root
,
false
,
stat
)
if
err
!=
nil
{
return
""
,
err
}
defer
f
.
Close
()
fileAdder
,
err
:=
NewAdder
(
n
.
Context
(),
n
.
Pinning
,
n
.
Blockstore
,
n
.
DAG
)
if
err
!=
nil
{
return
""
,
err
}
err
=
fileAdder
.
addFileNode
(
filepath
.
Base
(
root
),
f
)
if
err
!=
nil
{
return
""
,
err
}
nd
,
err
:=
fileAdder
.
Finalize
()
if
err
!=
nil
{
return
""
,
err
}
return
nd
.
String
(),
nil
}
// AddWrapped adds data from a reader, and wraps it with a directory object
// to preserve the filename.
// Returns the path of the added file ("<dir hash>/filename"), the DAG node of
// the directory, and and error if any.
func
AddWrapped
(
n
*
core
.
IpfsNode
,
r
io
.
Reader
,
filename
string
)
(
string
,
ipld
.
Node
,
error
)
{
fileAdder
,
err
:=
NewAdder
(
n
.
Context
(),
n
.
Pinning
,
n
.
Blockstore
,
n
.
DAG
)
if
err
!=
nil
{
return
""
,
nil
,
err
}
fileAdder
.
Wrap
=
true
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
err
=
fileAdder
.
addFileNode
(
filename
,
files
.
NewReaderFile
(
r
))
if
err
!=
nil
{
return
""
,
nil
,
err
}
dagnode
,
err
:=
fileAdder
.
Finalize
()
if
err
!=
nil
{
return
""
,
nil
,
err
}
c
:=
dagnode
.
Cid
()
return
gopath
.
Join
(
c
.
String
(),
filename
),
dagnode
,
nil
}
func
(
adder
*
Adder
)
addNode
(
node
ipld
.
Node
,
path
string
)
error
{
// patch it into the root
if
path
==
""
{
...
...
core/coreunix/add_test.go
浏览文件 @
062f47ef
...
...
@@ -30,26 +30,6 @@ import (
const
testPeerID
=
"QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
func
TestAddRecursive
(
t
*
testing
.
T
)
{
r
:=
&
repo
.
Mock
{
C
:
config
.
Config
{
Identity
:
config
.
Identity
{
PeerID
:
testPeerID
,
// required by offline node
},
},
D
:
syncds
.
MutexWrap
(
datastore
.
NewMapDatastore
()),
}
node
,
err
:=
core
.
NewNode
(
context
.
Background
(),
&
core
.
BuildCfg
{
Repo
:
r
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
k
,
err
:=
AddR
(
node
,
"test/data"
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
else
if
k
!=
"QmWCCga8AbTyfAQ7pTnGT6JgmRMAB3Qp8ZmTEFi5q5o8jC"
{
t
.
Fatal
(
"keys do not match: "
,
k
)
}
}
func
TestAddGCLive
(
t
*
testing
.
T
)
{
r
:=
&
repo
.
Mock
{
C
:
config
.
Config
{
...
...
test/integration/addcat_test.go
浏览文件 @
062f47ef
...
...
@@ -13,14 +13,13 @@ import (
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
mock
"github.com/ipfs/go-ipfs/core/mock"
"github.com/ipfs/go-ipfs/thirdparty/unit"
testutil
"gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil"
pstore
"gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore"
random
"gx/ipfs/QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt/go-random"
files
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
mocknet
"gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock"
logging
"gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
)
...
...
@@ -120,6 +119,11 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
}
defer
catter
.
Close
()
adderApi
,
err
:=
coreapi
.
NewCoreAPI
(
adder
)
if
err
!=
nil
{
return
err
}
catterApi
,
err
:=
coreapi
.
NewCoreAPI
(
catter
)
if
err
!=
nil
{
return
err
...
...
@@ -140,17 +144,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
return
err
}
added
,
err
:=
coreunix
.
Add
(
adder
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
return
err
}
ap
,
err
:=
iface
.
ParsePath
(
added
)
added
,
err
:=
adderApi
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewBytesFile
(
data
))
if
err
!=
nil
{
return
err
}
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Get
(
ctx
,
a
p
)
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Get
(
ctx
,
a
dded
)
if
err
!=
nil
{
return
err
}
...
...
test/integration/bench_cat_test.go
浏览文件 @
062f47ef
...
...
@@ -10,13 +10,12 @@ import (
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
mock
"github.com/ipfs/go-ipfs/core/mock"
"github.com/ipfs/go-ipfs/thirdparty/unit"
testutil
"gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil"
pstore
"gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore"
files
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
mocknet
"gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock"
)
...
...
@@ -66,6 +65,11 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
}
defer
catter
.
Close
()
adderApi
,
err
:=
coreapi
.
NewCoreAPI
(
adder
)
if
err
!=
nil
{
return
err
}
catterApi
,
err
:=
coreapi
.
NewCoreAPI
(
catter
)
if
err
!=
nil
{
return
err
...
...
@@ -86,18 +90,13 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
return
err
}
added
,
err
:=
coreunix
.
Add
(
adder
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
return
err
}
ap
,
err
:=
iface
.
ParsePath
(
added
)
added
,
err
:=
adderApi
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewBytesFile
(
data
))
if
err
!=
nil
{
return
err
}
b
.
StartTimer
()
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Get
(
ctx
,
a
p
)
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Get
(
ctx
,
a
dded
)
if
err
!=
nil
{
return
err
}
...
...
test/integration/three_legged_cat_test.go
浏览文件 @
062f47ef
...
...
@@ -11,13 +11,12 @@ import (
core
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
"github.com/ipfs/go-ipfs/core/coreapi/interface"
coreunix
"github.com/ipfs/go-ipfs/core/coreunix"
mock
"github.com/ipfs/go-ipfs/core/mock"
"github.com/ipfs/go-ipfs/thirdparty/unit"
testutil
"gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil"
pstore
"gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore"
files
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
mocknet
"gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock"
)
...
...
@@ -103,6 +102,11 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
}
defer
catter
.
Close
()
adderApi
,
err
:=
coreapi
.
NewCoreAPI
(
adder
)
if
err
!=
nil
{
return
err
}
catterApi
,
err
:=
coreapi
.
NewCoreAPI
(
catter
)
if
err
!=
nil
{
return
err
...
...
@@ -119,17 +123,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
return
err
}
added
,
err
:=
coreunix
.
Add
(
adder
,
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
return
err
}
ap
,
err
:=
iface
.
ParsePath
(
added
)
added
,
err
:=
adderApi
.
Unixfs
()
.
Add
(
ctx
,
files
.
NewBytesFile
(
data
))
if
err
!=
nil
{
return
err
}
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Get
(
ctx
,
a
p
)
readerCatted
,
err
:=
catterApi
.
Unixfs
()
.
Get
(
ctx
,
a
dded
)
if
err
!=
nil
{
return
err
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论