Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Levin Zimmermann
go-fuse
Commits
18bf653e
Commit
18bf653e
authored
Mar 22, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodefs: add Mount convenience function
parent
d93e94d8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
43 deletions
+63
-43
nodefs/api.go
nodefs/api.go
+3
-0
nodefs/cache_test.go
nodefs/cache_test.go
+6
-14
nodefs/example_test.go
nodefs/example_test.go
+5
-5
nodefs/interrupt_test.go
nodefs/interrupt_test.go
+4
-13
nodefs/mount.go
nodefs/mount.go
+39
-0
nodefs/zip_test.go
nodefs/zip_test.go
+6
-11
No files found.
nodefs/api.go
View file @
18bf653e
...
@@ -308,6 +308,9 @@ type FileHandle interface {
...
@@ -308,6 +308,9 @@ type FileHandle interface {
// Options sets options for the entire filesystem
// Options sets options for the entire filesystem
type
Options
struct
{
type
Options
struct
{
// MountOptions contain the options for mounting the fuse server
fuse
.
MountOptions
// If set to nonnil, this defines the overall entry timeout
// If set to nonnil, this defines the overall entry timeout
// for the file system. See fuse.EntryOut for more information.
// for the file system. See fuse.EntryOut for more information.
EntryTimeout
*
time
.
Duration
EntryTimeout
*
time
.
Duration
...
...
nodefs/cache_test.go
View file @
18bf653e
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"context"
"context"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"sync"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -84,28 +85,19 @@ func (r *keepCacheRoot) OnAdd(ctx context.Context) {
...
@@ -84,28 +85,19 @@ func (r *keepCacheRoot) OnAdd(ctx context.Context) {
func
TestKeepCache
(
t
*
testing
.
T
)
{
func
TestKeepCache
(
t
*
testing
.
T
)
{
mntDir
:=
testutil
.
TempDir
()
mntDir
:=
testutil
.
TempDir
()
defer
os
.
RemoveAll
(
mntDir
)
sec
:=
time
.
Second
sec
:=
time
.
Second
root
:=
&
keepCacheRoot
{}
root
:=
&
keepCacheRoot
{}
rawFS
:=
NewNodeFS
(
root
,
&
Options
{
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
},
FirstAutomaticIno
:
1
,
FirstAutomaticIno
:
1
,
AttrTimeout
:
&
sec
,
AttrTimeout
:
&
sec
,
EntryTimeout
:
&
sec
,
EntryTimeout
:
&
sec
,
})
})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
server
.
Unmount
()
defer
server
.
Unmount
()
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
c1
,
err
:=
ioutil
.
ReadFile
(
mntDir
+
"/keep"
)
c1
,
err
:=
ioutil
.
ReadFile
(
mntDir
+
"/keep"
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"read keep 1: %v"
,
err
)
t
.
Fatalf
(
"read keep 1: %v"
,
err
)
...
...
nodefs/example_test.go
View file @
18bf653e
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
// An example of creating a loopback file system, and mounting it onto
// An example of creating a loopback file system, and mounting it onto
// a directory
// a directory
func
Example
NewNodeFS
()
{
func
Example
Mount
()
{
mntDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
mntDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
home
:=
os
.
Getenv
(
"HOME"
)
home
:=
os
.
Getenv
(
"HOME"
)
...
@@ -23,14 +23,14 @@ func ExampleNewNodeFS() {
...
@@ -23,14 +23,14 @@ func ExampleNewNodeFS() {
log
.
Panic
(
err
)
log
.
Panic
(
err
)
}
}
rawFS
:=
NewNodeFS
(
root
,
&
Options
{})
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
MountOptions
:
fuse
.
MountOptions
{
Debug
:
true
}
,
&
fuse
.
MountOptions
{
Debug
:
true
})
})
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Panic
(
err
)
log
.
Panic
(
err
)
}
}
log
.
Printf
(
"Mounted %s as loopback on %s"
,
home
,
mntDir
)
log
.
Printf
(
"Mounted %s as loopback on %s"
,
home
,
mntDir
)
log
.
Printf
(
"Unmount by calling 'fusermount -u %s'"
,
mntDir
)
log
.
Printf
(
"Unmount by calling 'fusermount -u %s'"
,
mntDir
)
server
.
Serve
()
server
.
Wait
()
}
}
nodefs/interrupt_test.go
View file @
18bf653e
...
@@ -53,26 +53,17 @@ func TestInterrupt(t *testing.T) {
...
@@ -53,26 +53,17 @@ func TestInterrupt(t *testing.T) {
defer
os
.
Remove
(
mntDir
)
defer
os
.
Remove
(
mntDir
)
root
:=
&
interruptRoot
{}
root
:=
&
interruptRoot
{}
_
=
time
.
Second
oneSec
:=
time
.
Second
oneSec
:=
time
.
Second
rawFS
:=
NewNodeFS
(
root
,
&
Options
{
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
// NOSUBMIT - should run all tests without cache too
MountOptions
:
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
},
EntryTimeout
:
&
oneSec
,
EntryTimeout
:
&
oneSec
,
AttrTimeout
:
&
oneSec
,
AttrTimeout
:
&
oneSec
,
})
})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
server
.
Unmount
()
defer
server
.
Unmount
()
cmd
:=
exec
.
Command
(
"cat"
,
mntDir
+
"/file"
)
cmd
:=
exec
.
Command
(
"cat"
,
mntDir
+
"/file"
)
...
...
nodefs/mount.go
0 → 100644
View file @
18bf653e
// Copyright 2019 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
nodefs
import
(
"time"
"github.com/hanwen/go-fuse/fuse"
)
// Mount mounts the given NodeFS on the directory, and starts serving
// requests. This is a convenience wrapper around NewNodeFS and
// fuse.NewServer. If nil is given as options, default settings are
// applied, which are 1 second entry and attribute timeout.
func
Mount
(
dir
string
,
root
DirOperations
,
options
*
Options
)
(
*
fuse
.
Server
,
error
)
{
if
options
==
nil
{
oneSec
:=
time
.
Second
options
=
&
Options
{
EntryTimeout
:
&
oneSec
,
AttrTimeout
:
&
oneSec
,
}
}
rawFS
:=
NewNodeFS
(
root
,
options
)
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
dir
,
&
options
.
MountOptions
)
if
err
!=
nil
{
return
nil
,
err
}
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
// XXX should shutdown the serve loop?
return
nil
,
err
}
return
server
,
nil
}
nodefs/zip_test.go
View file @
18bf653e
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"bytes"
"bytes"
"context"
"context"
"io/ioutil"
"io/ioutil"
"os"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"strings"
"strings"
...
@@ -63,23 +64,17 @@ func TestZipFS(t *testing.T) {
...
@@ -63,23 +64,17 @@ func TestZipFS(t *testing.T) {
root
:=
&
zipRoot
{
r
:
r
}
root
:=
&
zipRoot
{
r
:
r
}
mntDir
:=
testutil
.
TempDir
()
mntDir
:=
testutil
.
TempDir
()
defer
os
.
Remove
(
mntDir
)
rawFS
:=
NewNodeFS
(
root
,
&
Options
{
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
},
FirstAutomaticIno
:
1
,
FirstAutomaticIno
:
1
,
})
})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
defer
server
.
Unmount
()
defer
server
.
Unmount
()
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
k
,
v
:=
range
testData
{
for
k
,
v
:=
range
testData
{
c
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
mntDir
,
k
))
c
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
mntDir
,
k
))
if
err
!=
nil
{
if
err
!=
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