Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
51607243
Unverified
提交
51607243
authored
7月 16, 2018
作者:
Whyrusleeping
提交者:
GitHub
7月 16, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5170 from schomatis/feat/mfs/root-val-as-dir
mfs: make `Root` value a `Directory`
上级
61d08eea
f5e7fe28
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
34 行增加
和
60 行删除
+34
-60
gc.go
core/corerepo/gc.go
+1
-1
add.go
core/coreunix/add.go
+4
-6
ipns_unix.go
fuse/ipns/ipns_unix.go
+1
-8
mfs_test.go
mfs/mfs_test.go
+11
-11
ops.go
mfs/ops.go
+5
-7
system.go
mfs/system.go
+12
-27
没有找到文件。
core/corerepo/gc.go
浏览文件 @
51607243
...
...
@@ -71,7 +71,7 @@ func NewGC(n *core.IpfsNode) (*GC, error) {
}
func
BestEffortRoots
(
filesRoot
*
mfs
.
Root
)
([]
*
cid
.
Cid
,
error
)
{
rootDag
,
err
:=
filesRoot
.
Get
Value
()
.
GetNode
()
rootDag
,
err
:=
filesRoot
.
Get
Directory
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
core/coreunix/add.go
浏览文件 @
51607243
...
...
@@ -145,7 +145,7 @@ func (adder *Adder) RootNode() (ipld.Node, error) {
if
err
!=
nil
{
return
nil
,
err
}
root
,
err
:=
mr
.
Get
Value
()
.
GetNode
()
root
,
err
:=
mr
.
Get
Directory
()
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -200,7 +200,8 @@ func (adder *Adder) Finalize() (ipld.Node, error) {
if
err
!=
nil
{
return
nil
,
err
}
root
:=
mr
.
GetValue
()
var
root
mfs
.
FSNode
root
=
mr
.
GetDirectory
()
err
=
root
.
Flush
()
if
err
!=
nil
{
...
...
@@ -225,10 +226,7 @@ func (adder *Adder) Finalize() (ipld.Node, error) {
return
nil
,
err
}
dir
,
ok
:=
mr
.
GetValue
()
.
(
*
mfs
.
Directory
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"root is not a directory"
)
}
dir
:=
mr
.
GetDirectory
()
root
,
err
=
dir
.
Child
(
name
)
if
err
!=
nil
{
...
...
fuse/ipns/ipns_unix.go
浏览文件 @
51607243
...
...
@@ -118,14 +118,7 @@ func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string
rt
.
root
=
root
switch
val
:=
root
.
GetValue
()
.
(
type
)
{
case
*
mfs
.
Directory
:
return
&
Directory
{
dir
:
val
},
nil
case
*
mfs
.
File
:
return
&
FileNode
{
fi
:
val
},
nil
default
:
return
nil
,
errors
.
New
(
"unrecognized type"
)
}
return
&
Directory
{
dir
:
root
.
GetDirectory
()},
nil
}
type
keyRoot
struct
{
...
...
mfs/mfs_test.go
浏览文件 @
51607243
...
...
@@ -213,7 +213,7 @@ func TestBasic(t *testing.T) {
defer
cancel
()
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
rootdir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
rootdir
:=
rt
.
Get
Directory
(
)
// test making a basic dir
_
,
err
:=
rootdir
.
Mkdir
(
"a"
)
...
...
@@ -243,7 +243,7 @@ func TestMkdir(t *testing.T) {
defer
cancel
()
_
,
rt
:=
setupRoot
(
ctx
,
t
)
rootdir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
rootdir
:=
rt
.
Get
Directory
(
)
dirsToMake
:=
[]
string
{
"a"
,
"B"
,
"foo"
,
"bar"
,
"cats"
,
"fish"
}
sort
.
Strings
(
dirsToMake
)
// sort for easy comparing later
...
...
@@ -281,7 +281,7 @@ func TestDirectoryLoadFromDag(t *testing.T) {
defer
cancel
()
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
rootdir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
rootdir
:=
rt
.
Get
Directory
(
)
nd
:=
getRandFile
(
t
,
ds
,
1000
)
err
:=
ds
.
Add
(
ctx
,
nd
)
...
...
@@ -373,7 +373,7 @@ func TestMfsFile(t *testing.T) {
defer
cancel
()
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
rootdir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
rootdir
:=
rt
.
Get
Directory
(
)
fisize
:=
1000
nd
:=
getRandFile
(
t
,
ds
,
1000
)
...
...
@@ -686,7 +686,7 @@ func actorReadFile(d *Directory) error {
}
func
testActor
(
rt
*
Root
,
iterations
int
,
errs
chan
error
)
{
d
:=
rt
.
Get
Value
()
.
(
*
Directory
)
d
:=
rt
.
Get
Directory
(
)
for
i
:=
0
;
i
<
iterations
;
i
++
{
switch
rand
.
Intn
(
5
)
{
case
0
:
...
...
@@ -763,7 +763,7 @@ func TestConcurrentWriteAndFlush(t *testing.T) {
defer
cancel
()
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
d
:=
mkdirP
(
t
,
rt
.
Get
Value
()
.
(
*
Directory
),
"foo/bar/baz"
)
d
:=
mkdirP
(
t
,
rt
.
Get
Directory
(
),
"foo/bar/baz"
)
fn
:=
fileNodeFromReader
(
t
,
ds
,
bytes
.
NewBuffer
(
nil
))
err
:=
d
.
AddChild
(
"file"
,
fn
)
if
err
!=
nil
{
...
...
@@ -786,7 +786,7 @@ func TestConcurrentWriteAndFlush(t *testing.T) {
}()
for
i
:=
0
;
i
<
nloops
;
i
++
{
_
,
err
:=
rt
.
Get
Value
()
.
GetNode
()
_
,
err
:=
rt
.
Get
Directory
()
.
GetNode
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -800,7 +800,7 @@ func TestFlushing(t *testing.T) {
defer
cancel
()
_
,
rt
:=
setupRoot
(
ctx
,
t
)
dir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
dir
:=
rt
.
Get
Directory
(
)
c
:=
mkdirP
(
t
,
dir
,
"a/b/c"
)
d
:=
mkdirP
(
t
,
dir
,
"a/b/d"
)
e
:=
mkdirP
(
t
,
dir
,
"a/b/e"
)
...
...
@@ -901,7 +901,7 @@ func TestConcurrentReads(t *testing.T) {
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
rootdir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
rootdir
:=
rt
.
Get
Directory
(
)
path
:=
"a/b/c"
d
:=
mkdirP
(
t
,
rootdir
,
path
)
...
...
@@ -976,7 +976,7 @@ func TestConcurrentWrites(t *testing.T) {
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
rootdir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
rootdir
:=
rt
.
Get
Directory
(
)
path
:=
"a/b/c"
d
:=
mkdirP
(
t
,
rootdir
,
path
)
...
...
@@ -1011,7 +1011,7 @@ func TestFileDescriptors(t *testing.T) {
defer
cancel
()
ds
,
rt
:=
setupRoot
(
ctx
,
t
)
dir
:=
rt
.
Get
Value
()
.
(
*
Directory
)
dir
:=
rt
.
Get
Directory
(
)
nd
:=
dag
.
NodeWithData
(
ft
.
FilePBData
(
nil
,
0
))
fi
,
err
:=
NewFile
(
"test"
,
nd
,
dir
,
ds
)
...
...
mfs/ops.go
浏览文件 @
51607243
package
mfs
import
(
"errors"
"fmt"
"os"
gopath
"path"
...
...
@@ -129,7 +128,7 @@ func Mkdir(r *Root, pth string, opts MkdirOpts) error {
return
fmt
.
Errorf
(
"cannot create directory '/': Already exists"
)
}
cur
:=
r
.
Get
Value
()
.
(
*
Directory
)
cur
:=
r
.
Get
Directory
(
)
for
i
,
d
:=
range
parts
[
:
len
(
parts
)
-
1
]
{
fsn
,
err
:=
cur
.
Child
(
d
)
if
err
==
os
.
ErrNotExist
&&
opts
.
Mkparents
{
...
...
@@ -172,12 +171,11 @@ func Mkdir(r *Root, pth string, opts MkdirOpts) error {
return
nil
}
// Lookup extracts the root directory and performs a lookup under it.
// TODO: Now that the root is always a directory, can this function
// be collapsed with `DirLookup`? Or at least be made a method of `Root`?
func
Lookup
(
r
*
Root
,
path
string
)
(
FSNode
,
error
)
{
dir
,
ok
:=
r
.
GetValue
()
.
(
*
Directory
)
if
!
ok
{
log
.
Errorf
(
"root not a dir: %#v"
,
r
.
GetValue
())
return
nil
,
errors
.
New
(
"root was not a directory"
)
}
dir
:=
r
.
GetDirectory
()
return
DirLookup
(
dir
,
path
)
}
...
...
mfs/system.go
浏览文件 @
51607243
...
...
@@ -50,17 +50,11 @@ type FSNode interface {
// Root represents the root of a filesystem tree.
type
Root
struct
{
// node is the merkledag root.
node
*
dag
.
ProtoNode
//
val represents the node. It can either be a File or a Directory
.
val
FSNode
//
Root directory of the MFS layout
.
dir
*
Directory
repub
*
Republisher
dserv
ipld
.
DAGService
Type
string
}
// PubFunc is the function used by the `publish()` method.
...
...
@@ -77,9 +71,7 @@ func NewRoot(parent context.Context, ds ipld.DAGService, node *dag.ProtoNode, pf
}
root
:=
&
Root
{
node
:
node
,
repub
:
repub
,
dserv
:
ds
,
}
pbn
,
err
:=
ft
.
FromBytes
(
node
.
Data
())
...
...
@@ -90,33 +82,29 @@ func NewRoot(parent context.Context, ds ipld.DAGService, node *dag.ProtoNode, pf
switch
pbn
.
GetType
()
{
case
ft
.
TDirectory
,
ft
.
THAMTShard
:
rval
,
err
:=
NewDirectory
(
parent
,
node
.
String
(),
node
,
root
,
ds
)
newDir
,
err
:=
NewDirectory
(
parent
,
node
.
String
(),
node
,
root
,
ds
)
if
err
!=
nil
{
return
nil
,
err
}
root
.
val
=
rval
root
.
dir
=
newDir
case
ft
.
TFile
,
ft
.
TMetadata
,
ft
.
TRaw
:
fi
,
err
:=
NewFile
(
node
.
String
(),
node
,
root
,
ds
)
if
err
!=
nil
{
return
nil
,
err
}
root
.
val
=
fi
return
nil
,
fmt
.
Errorf
(
"root can't be a file (unixfs type: %s)"
,
pbn
.
GetType
())
default
:
return
nil
,
fmt
.
Errorf
(
"unrecognized unixfs type: %s"
,
pbn
.
GetType
())
}
return
root
,
nil
}
// Get
Value returns the value of Root
.
func
(
kr
*
Root
)
Get
Value
()
FSNode
{
return
kr
.
val
// Get
Directory returns the root directory
.
func
(
kr
*
Root
)
Get
Directory
()
*
Directory
{
return
kr
.
dir
}
// Flush signals that an update has occurred since the last publish,
// and updates the Root republisher.
func
(
kr
*
Root
)
Flush
()
error
{
nd
,
err
:=
kr
.
Get
Value
()
.
GetNode
()
nd
,
err
:=
kr
.
Get
Directory
()
.
GetNode
()
if
err
!=
nil
{
return
err
}
...
...
@@ -136,10 +124,7 @@ func (kr *Root) Flush() error {
// A better implemented mfs system (one that does smarter internal caching and
// refcounting) shouldnt need this method.
func
(
kr
*
Root
)
FlushMemFree
(
ctx
context
.
Context
)
error
{
dir
,
ok
:=
kr
.
GetValue
()
.
(
*
Directory
)
if
!
ok
{
return
fmt
.
Errorf
(
"invalid mfs structure, root should be a directory"
)
}
dir
:=
kr
.
GetDirectory
()
if
err
:=
dir
.
Flush
();
err
!=
nil
{
return
err
...
...
@@ -160,7 +145,7 @@ func (kr *Root) FlushMemFree(ctx context.Context) error {
// closeChild implements the childCloser interface, and signals to the publisher that
// there are changes ready to be published.
func
(
kr
*
Root
)
closeChild
(
name
string
,
nd
ipld
.
Node
,
sync
bool
)
error
{
err
:=
kr
.
dserv
.
Add
(
context
.
TODO
(),
nd
)
err
:=
kr
.
GetDirectory
()
.
dserv
.
Add
(
context
.
TODO
(),
nd
)
if
err
!=
nil
{
return
err
}
...
...
@@ -172,7 +157,7 @@ func (kr *Root) closeChild(name string, nd ipld.Node, sync bool) error {
}
func
(
kr
*
Root
)
Close
()
error
{
nd
,
err
:=
kr
.
Get
Value
()
.
GetNode
()
nd
,
err
:=
kr
.
Get
Directory
()
.
GetNode
()
if
err
!=
nil
{
return
err
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论