Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9215955e
提交
9215955e
authored
3月 13, 2019
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: initial MFS impl
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
245c40b8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
177 行增加
和
0 行删除
+177
-0
coreapi.go
core/coreapi/coreapi.go
+7
-0
mfs.go
core/coreapi/mfs.go
+170
-0
没有找到文件。
core/coreapi/coreapi.go
浏览文件 @
9215955e
...
...
@@ -17,6 +17,7 @@ import (
"context"
"errors"
"fmt"
"github.com/ipfs/go-mfs"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/namesys"
...
...
@@ -71,6 +72,8 @@ type CoreAPI struct {
checkPublishAllowed
func
()
error
checkOnline
func
(
allowOffline
bool
)
error
filesRoot
*
mfs
.
Root
// TODO: option filtering
// ONLY for re-applying options in WithOptions, DO NOT USE ANYWHERE ELSE
nd
*
core
.
IpfsNode
parentOpts
options
.
ApiSettings
...
...
@@ -119,6 +122,10 @@ func (api *CoreAPI) Object() coreiface.ObjectAPI {
return
(
*
ObjectAPI
)(
api
)
}
func
(
api
*
CoreAPI
)
Mfs
()
coreiface
.
MfsAPI
{
return
(
*
MfsAPI
)(
api
)
}
// Pin returns the PinAPI interface implementation backed by the go-ipfs node
func
(
api
*
CoreAPI
)
Pin
()
coreiface
.
PinAPI
{
return
(
*
PinAPI
)(
api
)
...
...
core/coreapi/mfs.go
0 → 100644
浏览文件 @
9215955e
package
coreapi
import
(
"context"
"fmt"
"github.com/ipfs/go-mfs"
"github.com/pkg/errors"
"os"
gopath
"path"
"time"
coreiface
"github.com/ipfs/interface-go-ipfs-core"
)
const
defaultFilePerm
=
0644
const
defaultDirPerm
=
0755
type
MfsAPI
CoreAPI
type
fileNodeInfo
struct
{
l
mfs
.
NodeListing
}
func
(
i
*
fileNodeInfo
)
Name
()
string
{
return
i
.
l
.
Name
//TODO: check what is really returned here
}
func
(
i
*
fileNodeInfo
)
Size
()
int64
{
return
i
.
l
.
Size
}
func
(
i
*
fileNodeInfo
)
Mode
()
os
.
FileMode
{
return
defaultFilePerm
}
func
(
i
*
fileNodeInfo
)
ModTime
()
time
.
Time
{
return
time
.
Unix
(
0
,
0
)
}
func
(
i
*
fileNodeInfo
)
IsDir
()
bool
{
return
mfs
.
NodeType
(
i
.
l
.
Type
)
==
mfs
.
TDir
}
func
(
i
*
fileNodeInfo
)
Sys
()
interface
{}
{
return
i
.
l
}
func
(
api
*
MfsAPI
)
Create
(
ctx
context
.
Context
,
path
coreiface
.
MfsPath
)
(
coreiface
.
File
,
error
)
{
return
api
.
OpenFile
(
ctx
,
path
,
os
.
O_CREATE
|
os
.
O_WRONLY
,
defaultFilePerm
)
}
func
(
api
*
MfsAPI
)
Open
(
ctx
context
.
Context
,
path
coreiface
.
MfsPath
)
(
coreiface
.
File
,
error
)
{
return
api
.
OpenFile
(
ctx
,
path
,
os
.
O_RDWR
,
defaultFilePerm
)
}
func
(
api
*
MfsAPI
)
OpenFile
(
ctx
context
.
Context
,
path
coreiface
.
MfsPath
,
flag
int
,
perm
os
.
FileMode
)
(
coreiface
.
File
,
error
)
{
panic
(
"implement me"
)
}
func
(
api
*
MfsAPI
)
Stat
(
ctx
context
.
Context
,
path
coreiface
.
MfsPath
)
(
os
.
FileInfo
,
error
)
{
fsn
,
err
:=
mfs
.
Lookup
(
api
.
filesRoot
,
path
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
nd
,
err
:=
fsn
.
GetNode
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
fileNodeInfo
{
l
:
mfs
.
NodeListing
{
Name
:
path
.
String
(),
Type
:
int
(
fsn
.
Type
()),
Size
:
-
1
,
//TODO
Hash
:
nd
.
Cid
()
.
String
(),
},
},
nil
}
func
(
api
*
MfsAPI
)
Rename
(
ctx
context
.
Context
,
oldpath
,
newpath
coreiface
.
MfsPath
)
error
{
flush
:=
false
//TODO
err
:=
mfs
.
Mv
(
api
.
filesRoot
,
oldpath
.
String
(),
newpath
.
String
())
if
err
==
nil
&&
flush
{
err
=
mfs
.
FlushPath
(
api
.
filesRoot
,
"/"
)
}
return
err
}
func
(
api
*
MfsAPI
)
Remove
(
ctx
context
.
Context
,
path
coreiface
.
MfsPath
)
error
{
if
path
.
String
()
==
"/"
{
return
fmt
.
Errorf
(
"cannot delete root"
)
}
dir
,
name
:=
gopath
.
Split
(
path
.
String
())
parent
,
err
:=
mfs
.
Lookup
(
api
.
filesRoot
,
dir
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"parent lookup: %s"
,
err
)
}
pdir
,
ok
:=
parent
.
(
*
mfs
.
Directory
)
if
!
ok
{
return
fmt
.
Errorf
(
"no such file or directory: %s"
,
path
)
}
// TODO: force
// get child node by name, when the node is corrupted and nonexistent,
// it will return specific error.
child
,
err
:=
pdir
.
Child
(
name
)
if
err
!=
nil
{
return
err
}
dashr
:=
true
// TODO: make into an option
switch
child
.
(
type
)
{
case
*
mfs
.
Directory
:
if
!
dashr
{
return
fmt
.
Errorf
(
"%s is a directory, use -r to remove directories"
,
path
)
}
}
err
=
pdir
.
Unlink
(
name
)
if
err
!=
nil
{
return
err
}
return
pdir
.
Flush
()
//TODO: setting for flush
}
func
(
api
*
MfsAPI
)
ReadDir
(
ctx
context
.
Context
,
path
coreiface
.
MfsPath
)
([]
os
.
FileInfo
,
error
)
{
fsn
,
err
:=
mfs
.
Lookup
(
api
.
filesRoot
,
path
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
switch
fsn
:=
fsn
.
(
type
)
{
case
*
mfs
.
Directory
:
lst
,
err
:=
fsn
.
List
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
out
:=
make
([]
os
.
FileInfo
,
len
(
lst
))
for
i
,
v
:=
range
lst
{
out
[
i
]
=
&
fileNodeInfo
{
l
:
v
,
}
}
return
out
,
nil
default
:
return
nil
,
errors
.
New
(
"readdir: unsupported node type"
)
}
}
func
(
api
*
MfsAPI
)
MkdirAll
(
path
coreiface
.
MfsPath
,
perm
os
.
FileMode
)
error
{
return
mfs
.
Mkdir
(
api
.
filesRoot
,
path
.
String
(),
mfs
.
MkdirOpts
{
Mkparents
:
true
,
Flush
:
false
,
//CidBuilder: prefix, TODO
})
}
func
(
api
*
MfsAPI
)
core
()
coreiface
.
CoreAPI
{
return
(
*
CoreAPI
)(
api
)
}
var
_
os
.
FileInfo
=
&
fileNodeInfo
{}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论