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 {
// Options sets options for the entire filesystem
type
Options
struct
{
// MountOptions contain the options for mounting the fuse server
fuse
.
MountOptions
// If set to nonnil, this defines the overall entry timeout
// for the file system. See fuse.EntryOut for more information.
EntryTimeout
*
time
.
Duration
...
...
nodefs/cache_test.go
View file @
18bf653e
...
...
@@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
"time"
...
...
@@ -84,28 +85,19 @@ func (r *keepCacheRoot) OnAdd(ctx context.Context) {
func
TestKeepCache
(
t
*
testing
.
T
)
{
mntDir
:=
testutil
.
TempDir
()
defer
os
.
RemoveAll
(
mntDir
)
sec
:=
time
.
Second
root
:=
&
keepCacheRoot
{}
rawFS
:=
NewNodeFS
(
root
,
&
Options
{
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
},
FirstAutomaticIno
:
1
,
AttrTimeout
:
&
sec
,
EntryTimeout
:
&
sec
,
})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
server
.
Unmount
()
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
c1
,
err
:=
ioutil
.
ReadFile
(
mntDir
+
"/keep"
)
if
err
!=
nil
{
t
.
Fatalf
(
"read keep 1: %v"
,
err
)
...
...
nodefs/example_test.go
View file @
18bf653e
...
...
@@ -14,7 +14,7 @@ import (
// An example of creating a loopback file system, and mounting it onto
// a directory
func
Example
NewNodeFS
()
{
func
Example
Mount
()
{
mntDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
home
:=
os
.
Getenv
(
"HOME"
)
...
...
@@ -23,14 +23,14 @@ func ExampleNewNodeFS() {
log
.
Panic
(
err
)
}
rawFS
:=
NewNodeFS
(
root
,
&
Options
{})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
true
})
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
true
}
,
})
if
err
!=
nil
{
log
.
Panic
(
err
)
}
log
.
Printf
(
"Mounted %s as loopback on %s"
,
home
,
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) {
defer
os
.
Remove
(
mntDir
)
root
:=
&
interruptRoot
{}
_
=
time
.
Second
oneSec
:=
time
.
Second
rawFS
:=
NewNodeFS
(
root
,
&
Options
{
// NOSUBMIT - should run all tests without cache too
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
},
EntryTimeout
:
&
oneSec
,
AttrTimeout
:
&
oneSec
,
})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
server
.
Unmount
()
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 (
"bytes"
"context"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
...
...
@@ -63,23 +64,17 @@ func TestZipFS(t *testing.T) {
root
:=
&
zipRoot
{
r
:
r
}
mntDir
:=
testutil
.
TempDir
()
rawFS
:=
NewNodeFS
(
root
,
&
Options
{
defer
os
.
Remove
(
mntDir
)
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
},
FirstAutomaticIno
:
1
,
})
server
,
err
:=
fuse
.
NewServer
(
rawFS
,
mntDir
,
&
fuse
.
MountOptions
{
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
server
.
Unmount
()
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
k
,
v
:=
range
testData
{
c
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
mntDir
,
k
))
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