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
883322c5
Commit
883322c5
authored
Mar 19, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodefs: add test for FOPEN_KEEP_CACHE
parent
485a73b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
0 deletions
+133
-0
nodefs/cache_test.go
nodefs/cache_test.go
+133
-0
No files found.
nodefs/cache_test.go
0 → 100644
View file @
883322c5
// 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
(
"bytes"
"context"
"fmt"
"io/ioutil"
"sync"
"testing"
"time"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
)
type
keepCacheFile
struct
{
DefaultOperations
keepCache
bool
mu
sync
.
Mutex
content
[]
byte
count
int
}
func
(
f
*
keepCacheFile
)
setContent
(
delta
int
)
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
f
.
count
+=
delta
f
.
content
=
[]
byte
(
fmt
.
Sprintf
(
"%010x"
,
f
.
count
))
}
func
(
f
*
keepCacheFile
)
Open
(
ctx
context
.
Context
,
flags
uint32
)
(
FileHandle
,
uint32
,
fuse
.
Status
)
{
var
fl
uint32
if
f
.
keepCache
{
fl
=
fuse
.
FOPEN_KEEP_CACHE
}
f
.
setContent
(
0
)
return
nil
,
fl
,
fuse
.
OK
}
func
(
f
*
keepCacheFile
)
GetAttr
(
ctx
context
.
Context
,
out
*
fuse
.
AttrOut
)
fuse
.
Status
{
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
out
.
Size
=
uint64
(
len
(
f
.
content
))
return
fuse
.
OK
}
func
(
f
*
keepCacheFile
)
Read
(
ctx
context
.
Context
,
fh
FileHandle
,
dest
[]
byte
,
off
int64
)
(
fuse
.
ReadResult
,
fuse
.
Status
)
{
f
.
setContent
(
1
)
f
.
mu
.
Lock
()
defer
f
.
mu
.
Unlock
()
return
fuse
.
ReadResultData
(
f
.
content
[
off
:
]),
fuse
.
OK
}
type
keepCacheRoot
struct
{
DefaultOperations
}
func
(
r
*
keepCacheRoot
)
OnAdd
()
{
i
:=
InodeOf
(
r
)
f1
:=
&
keepCacheFile
{
keepCache
:
true
,
}
f1
.
setContent
(
0
)
i
.
AddChild
(
"keep"
,
i
.
NewInode
(
f1
,
fuse
.
S_IFREG
,
FileID
{}),
true
)
f2
:=
&
keepCacheFile
{
keepCache
:
false
,
}
f2
.
setContent
(
0
)
i
.
AddChild
(
"nokeep"
,
i
.
NewInode
(
f2
,
fuse
.
S_IFREG
,
FileID
{}),
true
)
}
func
TestKeepCache
(
t
*
testing
.
T
)
{
mntDir
:=
testutil
.
TempDir
()
sec
:=
time
.
Second
rawFS
:=
NewNodeFS
(
&
keepCacheRoot
{},
&
Options
{
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
)
}
c2
,
err
:=
ioutil
.
ReadFile
(
mntDir
+
"/keep"
)
if
err
!=
nil
{
t
.
Fatalf
(
"read keep 2: %v"
,
err
)
}
if
bytes
.
Compare
(
c1
,
c2
)
!=
0
{
t
.
Errorf
(
"keep read 2 got %q want read 1 %q"
,
c2
,
c1
)
}
nc1
,
err
:=
ioutil
.
ReadFile
(
mntDir
+
"/nokeep"
)
if
err
!=
nil
{
t
.
Fatalf
(
"read keep 1: %v"
,
err
)
}
nc2
,
err
:=
ioutil
.
ReadFile
(
mntDir
+
"/nokeep"
)
if
err
!=
nil
{
t
.
Fatalf
(
"read keep 2: %v"
,
err
)
}
if
bytes
.
Compare
(
nc1
,
nc2
)
==
0
{
t
.
Errorf
(
"nokeep read 2 got %q want read 1 %q"
,
c2
,
c1
)
}
}
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