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-unixfs
Commits
0831928c
Commit
0831928c
authored
Jul 06, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using bazil.org/fuse
parent
e9bc9236
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
86 deletions
+92
-86
cli/mount.go
cli/mount.go
+1
-8
fuse/readonly/readonly.go
fuse/readonly/readonly.go
+91
-78
No files found.
cli/mount.go
View file @
0831928c
...
@@ -36,12 +36,5 @@ func mountCmd(c *commander.Command, inp []string) error {
...
@@ -36,12 +36,5 @@ func mountCmd(c *commander.Command, inp []string) error {
mp
:=
inp
[
0
]
mp
:=
inp
[
0
]
fmt
.
Printf
(
"Mounting at %s
\n
"
,
mp
)
fmt
.
Printf
(
"Mounting at %s
\n
"
,
mp
)
fs
:=
rofs
.
NewFileSystem
(
n
)
return
rofs
.
Mount
(
n
,
mp
)
s
,
err
:=
rofs
.
Mount
(
fs
,
mp
)
if
err
!=
nil
{
return
err
}
s
.
SetDebug
(
true
)
s
.
Serve
()
return
nil
}
}
fuse/readonly/readonly.go
View file @
0831928c
...
@@ -3,103 +3,116 @@
...
@@ -3,103 +3,116 @@
package
readonly
package
readonly
import
(
import
(
"github.com/hanwen/go-fuse/fuse"
"os"
"github.com/hanwen/go-fuse/fuse/nodefs"
"bazil.org/fuse"
"github.com/hanwen/go-fuse/fuse/pathfs"
"bazil.org/fuse/fs"
core
"github.com/jbenet/go-ipfs/core"
core
"github.com/jbenet/go-ipfs/core"
mdag
"github.com/jbenet/go-ipfs/merkledag"
)
)
type
FileSystem
struct
{
type
FileSystem
struct
{
Ipfs
*
core
.
IpfsNode
Ipfs
*
core
.
IpfsNode
pathfs
.
FileSystem
}
}
func
NewFileSystem
(
ipfs
*
core
.
IpfsNode
)
*
FileSystem
{
func
NewFileSystem
(
ipfs
*
core
.
IpfsNode
)
*
FileSystem
{
return
&
FileSystem
{
return
&
FileSystem
{
Ipfs
:
ipfs
}
Ipfs
:
ipfs
,
}
FileSystem
:
pathfs
.
NewDefaultFileSystem
(),
}
func
(
f
FileSystem
)
Root
()
(
fs
.
Node
,
fuse
.
Error
)
{
return
Root
{
Ipfs
:
f
.
Ipfs
},
nil
}
type
Root
struct
{
Ipfs
*
core
.
IpfsNode
}
func
(
Root
)
Attr
()
fuse
.
Attr
{
return
fuse
.
Attr
{
Inode
:
1
,
Mode
:
os
.
ModeDir
|
0111
}
// -rw+x
}
func
(
s
*
Root
)
Lookup
(
name
string
,
intr
fs
.
Intr
)
(
fs
.
Node
,
fuse
.
Error
)
{
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
return
Node
{
Ipfs
:
s
.
Ipfs
,
Nd
:
nd
},
nil
}
}
func
(
s
*
FileSystem
)
GetAttr
(
name
string
,
context
*
fuse
.
Context
)
(
*
fuse
.
Attr
,
fuse
.
Status
)
{
func
(
Root
)
ReadDir
(
intr
fs
.
Intr
)
([]
fuse
.
Dirent
,
fuse
.
Error
)
{
if
name
==
"/"
{
// -rw +x on root
return
nil
,
fuse
.
EPERM
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0111
},
fuse
.
OK
}
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
// links? say dir. could have data...
if
len
(
nd
.
Links
)
>
0
{
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFDIR
|
0555
},
fuse
.
OK
}
// size
size
,
_
:=
nd
.
Size
()
// file.
return
&
fuse
.
Attr
{
Mode
:
fuse
.
S_IFREG
|
0444
,
Size
:
uint64
(
size
),
},
fuse
.
OK
}
}
func
(
s
*
FileSystem
)
OpenDir
(
name
string
,
context
*
fuse
.
Context
)
(
c
[]
fuse
.
DirEntry
,
code
fuse
.
Status
)
{
type
Node
struct
{
if
name
==
"/"
{
// nope
Ipfs
*
core
.
IpfsNode
return
nil
,
fuse
.
EPERM
Nd
*
mdag
.
Node
}
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
ResolvePath
(
name
)
if
err
!=
nil
{
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
}
entries
:=
make
([]
fuse
.
DirEntry
,
len
(
nd
.
Links
))
for
i
,
link
:=
range
nd
.
Links
{
n
:=
link
.
Name
if
len
(
n
)
==
0
{
n
=
link
.
Hash
.
B58String
()
}
entries
[
i
]
=
fuse
.
DirEntry
{
Name
:
n
,
Mode
:
fuse
.
S_IFREG
|
0444
}
}
if
len
(
entries
)
>
0
{
return
entries
,
fuse
.
OK
}
return
nil
,
fuse
.
ENOENT
}
}
func
(
s
*
FileSystem
)
Open
(
name
string
,
flags
uint32
,
context
*
fuse
.
Context
)
(
func
(
s
Node
)
Attr
()
fuse
.
Attr
{
file
nodefs
.
File
,
code
fuse
.
Status
)
{
if
len
(
s
.
Nd
.
Links
)
>
0
{
return
fuse
.
Attr
{
Mode
:
os
.
ModeDir
|
0555
}
}
size
,
_
:=
s
.
Nd
.
Size
()
return
fuse
.
Attr
{
Mode
:
0444
,
Size
:
uint64
(
size
)}
}
// read only, bro!
func
(
s
*
Node
)
Lookup
(
name
string
,
intr
fs
.
Intr
)
(
fs
.
Node
,
fuse
.
Error
)
{
if
flags
&
fuse
.
O_ANYWRITE
!=
0
{
return
nil
,
fuse
.
EPERM
}
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
Resolve
Path
(
name
)
nd
,
err
:=
s
.
Ipfs
.
Resolver
.
Resolve
Links
(
s
.
Nd
,
[]
string
{
name
}
)
if
err
!=
nil
{
if
err
!=
nil
{
// todo: make this error more versatile.
// todo: make this error more versatile.
return
nil
,
fuse
.
ENOENT
return
nil
,
fuse
.
ENOENT
}
}
return
n
ode
fs
.
NewDataFile
([]
byte
(
nd
.
Data
)),
fuse
.
OK
return
N
ode
{
Ipfs
:
s
.
Ipfs
,
Nd
:
nd
},
nil
}
}
func
(
s
*
FileSystem
)
String
()
string
{
func
(
s
*
Node
)
ReadDir
(
intr
fs
.
Intr
)
([]
fuse
.
Dirent
,
fuse
.
Error
)
{
return
"IpfsReadOnly"
entries
:=
make
([]
fuse
.
Dirent
,
len
(
s
.
Nd
.
Links
))
for
i
,
link
:=
range
s
.
Nd
.
Links
{
n
:=
link
.
Name
if
len
(
n
)
==
0
{
n
=
link
.
Hash
.
B58String
()
}
entries
[
i
]
=
fuse
.
Dirent
{
Name
:
n
,
Type
:
fuse
.
DT_File
}
}
if
len
(
entries
)
>
0
{
return
entries
,
nil
}
return
nil
,
fuse
.
ENOENT
}
}
func
(
s
*
FileSystem
)
OnMount
(
nodeFs
*
pathfs
.
PathNodeFs
)
{
func
(
s
*
Node
)
ReadAll
(
intr
fs
.
Intr
)
([]
byte
,
fuse
.
Error
)
{
return
[]
byte
(
s
.
Nd
.
Data
),
nil
}
}
func
Mount
(
s
*
FileSystem
,
path
string
)
(
*
fuse
.
Server
,
error
)
{
rfs
:=
pathfs
.
NewReadonlyFileSystem
(
s
)
fs
:=
pathfs
.
NewPathNodeFs
(
rfs
,
nil
)
func
Mount
(
ipfs
*
core
.
IpfsNode
,
fpath
string
)
(
error
)
{
ser
,
_
,
err
:=
nodefs
.
MountRoot
(
path
,
fs
.
Root
(),
nil
)
return
ser
,
err
c
,
err
:=
fuse
.
Mount
(
fpath
)
if
err
!=
nil
{
return
err
}
defer
c
.
Close
()
err
=
fs
.
Serve
(
c
,
FileSystem
{
Ipfs
:
ipfs
})
if
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
}
}
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