Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6ff472be
提交
6ff472be
authored
11月 16, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mount: move Mount func into mount obj
上级
99f2378b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
81 行增加
和
62 行删除
+81
-62
mount_unix.go
fuse/ipns/mount_unix.go
+33
-27
mount.go
fuse/mount/mount.go
+17
-9
readonly_unix.go
fuse/readonly/readonly_unix.go
+31
-26
没有找到文件。
fuse/ipns/mount_unix.go
浏览文件 @
6ff472be
...
...
@@ -19,34 +19,12 @@ func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) (mount.Mount, err
log
.
Infof
(
"Mounting ipns at %s..."
,
fpath
)
// setup the Mount abstraction.
m
:=
mount
.
New
(
ipfs
.
Context
(),
fpath
,
unmount
)
m
:=
mount
.
New
(
ipfs
.
Context
(),
fpath
)
// go serve the mount
mount
.
ServeMount
(
m
,
func
(
m
mount
.
Mount
)
error
{
c
,
err
:=
fuse
.
Mount
(
fpath
)
if
err
!=
nil
{
return
err
}
defer
c
.
Close
()
fsys
,
err
:=
NewIpns
(
ipfs
,
ipfspath
)
if
err
!=
nil
{
return
err
}
log
.
Infof
(
"Mounted ipns at %s."
,
fpath
)
if
err
:=
fs
.
Serve
(
c
,
fsys
);
err
!=
nil
{
return
err
}
// check if the mount process has an error to report
<-
c
.
Ready
if
err
:=
c
.
MountError
;
err
!=
nil
{
return
err
}
return
nil
})
m
.
Mount
(
func
(
m
mount
.
Mount
)
error
{
return
internalMount
(
ipfs
,
fpath
,
ipfspath
)
},
internalUnmount
)
select
{
case
<-
m
.
Closed
()
:
...
...
@@ -61,9 +39,37 @@ func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) (mount.Mount, err
return
m
,
nil
}
// mount attempts to mount at the provided FUSE mount point
func
internalMount
(
ipfs
*
core
.
IpfsNode
,
fpath
string
,
ipfspath
string
)
error
{
c
,
err
:=
fuse
.
Mount
(
fpath
)
if
err
!=
nil
{
return
err
}
defer
c
.
Close
()
fsys
,
err
:=
NewIpns
(
ipfs
,
ipfspath
)
if
err
!=
nil
{
return
err
}
log
.
Infof
(
"Mounted ipns at %s."
,
fpath
)
if
err
:=
fs
.
Serve
(
c
,
fsys
);
err
!=
nil
{
return
err
}
// check if the mount process has an error to report
<-
c
.
Ready
if
err
:=
c
.
MountError
;
err
!=
nil
{
return
err
}
return
nil
}
// unmount attempts to unmount the provided FUSE mount point, forcibly
// if necessary.
func
unmount
(
point
string
)
error
{
func
internalUnmount
(
m
mount
.
Mount
)
error
{
point
:=
m
.
MountPoint
()
log
.
Infof
(
"Unmounting ipns at %s..."
,
point
)
var
cmd
*
exec
.
Cmd
...
...
fuse/mount/mount.go
浏览文件 @
6ff472be
...
...
@@ -19,23 +19,26 @@ type Mount interface {
// MountPoint is the path at which this mount is mounted
MountPoint
()
string
// Mount function sets up a mount + registers the unmount func
Mount
(
mount
MountFunc
,
unmount
UnmountFunc
)
// Unmount calls Close.
Unmount
()
error
ctxc
.
ContextCloser
}
// UnmountFunc is a function used to unmount a mount
type
UnmountFunc
func
(
mountpoint
string
)
error
// UnmountFunc is a function used to Unmount a mount
type
UnmountFunc
func
(
Mount
)
error
// MountFunc is a function used to Mount a mount
type
MountFunc
func
(
Mount
)
error
// New constructs a new Mount instance. ctx is a context to wait upon,
// the mountpoint is the directory that the mount was mounted at, and unmount
// in an UnmountFunc to perform the unmounting logic.
func
New
(
ctx
context
.
Context
,
mountpoint
string
,
unmount
UnmountFunc
)
Mount
{
m
:=
&
mount
{
mpoint
:
mountpoint
,
unmount
:
unmount
,
}
func
New
(
ctx
context
.
Context
,
mountpoint
string
)
Mount
{
m
:=
&
mount
{
mpoint
:
mountpoint
}
m
.
ContextCloser
=
ctxc
.
NewContextCloser
(
ctx
,
m
.
persistentUnmount
)
return
m
}
...
...
@@ -50,10 +53,14 @@ type mount struct {
// umount is called after the mount is closed.
// TODO this is hacky, make it better.
func
(
m
*
mount
)
persistentUnmount
()
error
{
// no unmount func.
if
m
.
unmount
==
nil
{
return
nil
}
// ok try to unmount a whole bunch of times...
for
i
:=
0
;
i
<
34
;
i
++
{
err
:=
m
.
unmount
(
m
.
mpoint
)
err
:=
m
.
unmount
(
m
)
if
err
==
nil
{
return
nil
}
...
...
@@ -72,8 +79,9 @@ func (m *mount) Unmount() error {
return
m
.
Close
()
}
func
ServeMount
(
m
Mount
,
mount
func
(
Mount
)
error
)
{
func
(
m
*
mount
)
Mount
(
mount
MountFunc
,
unmount
UnmountFunc
)
{
m
.
Children
()
.
Add
(
1
)
m
.
unmount
=
unmount
// go serve the mount
go
func
()
{
...
...
fuse/readonly/readonly_unix.go
浏览文件 @
6ff472be
...
...
@@ -165,32 +165,12 @@ func Mount(ipfs *core.IpfsNode, fpath string) (mount.Mount, error) {
log
.
Infof
(
"Mounting ipfs at %s..."
,
fpath
)
// setup the Mount abstraction.
m
:=
mount
.
New
(
ipfs
.
Context
(),
fpath
,
unmount
)
m
:=
mount
.
New
(
ipfs
.
Context
(),
fpath
)
// go serve the mount
mount
.
ServeMount
(
m
,
func
(
m
mount
.
Mount
)
error
{
c
,
err
:=
fuse
.
Mount
(
m
.
MountPoint
())
if
err
!=
nil
{
return
err
}
defer
c
.
Close
()
fsys
:=
FileSystem
{
Ipfs
:
ipfs
}
log
.
Infof
(
"Mounted ipfs at %s."
,
fpath
)
if
err
:=
fs
.
Serve
(
c
,
fsys
);
err
!=
nil
{
return
err
}
// check if the mount process has an error to report
<-
c
.
Ready
if
err
:=
c
.
MountError
;
err
!=
nil
{
m
.
Unmount
()
return
err
}
return
nil
})
m
.
Mount
(
func
(
m
mount
.
Mount
)
error
{
return
internalMount
(
ipfs
,
m
)
},
internalUnmount
)
select
{
case
<-
m
.
Closed
()
:
...
...
@@ -205,9 +185,34 @@ func Mount(ipfs *core.IpfsNode, fpath string) (mount.Mount, error) {
return
m
,
nil
}
// Unmount attempts to unmount the provided FUSE mount point, forcibly
// mount attempts to mount the provided FUSE mount point
func
internalMount
(
ipfs
*
core
.
IpfsNode
,
m
mount
.
Mount
)
error
{
c
,
err
:=
fuse
.
Mount
(
m
.
MountPoint
())
if
err
!=
nil
{
return
err
}
defer
c
.
Close
()
fsys
:=
FileSystem
{
Ipfs
:
ipfs
}
log
.
Infof
(
"Mounted ipfs at %s."
,
m
.
MountPoint
())
if
err
:=
fs
.
Serve
(
c
,
fsys
);
err
!=
nil
{
return
err
}
// check if the mount process has an error to report
<-
c
.
Ready
if
err
:=
c
.
MountError
;
err
!=
nil
{
m
.
Unmount
()
return
err
}
return
nil
}
// unmount attempts to unmount the provided FUSE mount point, forcibly
// if necessary.
func
unmount
(
point
string
)
error
{
func
internalUnmount
(
m
mount
.
Mount
)
error
{
point
:=
m
.
MountPoint
()
log
.
Infof
(
"Unmounting ipfs at %s..."
,
point
)
var
cmd
*
exec
.
Cmd
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论