Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jacobsa-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
Kirill Smelkov
jacobsa-fuse
Commits
0698d680
Commit
0698d680
authored
Mar 20, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flushFS.WriteFile
parent
b87740f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
5 deletions
+36
-5
samples/flushfs/flush_fs.go
samples/flushfs/flush_fs.go
+30
-2
samples/flushfs/flush_fs_test.go
samples/flushfs/flush_fs_test.go
+6
-3
No files found.
samples/flushfs/flush_fs.go
View file @
0698d680
...
...
@@ -15,6 +15,7 @@
package
flushfs
import
(
"fmt"
"os"
"sync"
...
...
@@ -40,8 +41,8 @@ const fooID = fuse.RootInodeID + 1
type
flushFS
struct
{
fuseutil
.
NotImplementedFileSystem
mu
sync
.
Mutex
foo
*
os
.
Fil
e
// GUARDED_BY(mu)
mu
sync
.
Mutex
foo
Contents
[]
byt
e
// GUARDED_BY(mu)
}
////////////////////////////////////////////////////////////////////////
...
...
@@ -140,3 +141,30 @@ func (fs *flushFS) OpenFile(
return
}
func
(
fs
*
flushFS
)
WriteFile
(
ctx
context
.
Context
,
req
*
fuse
.
WriteFileRequest
)
(
resp
*
fuse
.
WriteFileResponse
,
err
error
)
{
resp
=
&
fuse
.
WriteFileResponse
{}
fs
.
mu
.
Lock
()
defer
fs
.
mu
.
Unlock
()
// Ensure that the contents slice is long enough.
newLen
:=
int
(
req
.
Offset
)
+
len
(
req
.
Data
)
if
len
(
fs
.
fooContents
)
<
newLen
{
padding
:=
make
([]
byte
,
newLen
-
len
(
fs
.
fooContents
))
fs
.
fooContents
=
append
(
fs
.
fooContents
,
padding
...
)
}
// Copy in the data.
n
:=
copy
(
fs
.
fooContents
[
req
.
Offset
:
],
req
.
Data
)
// Sanity check.
if
n
!=
len
(
req
.
Data
)
{
panic
(
fmt
.
Sprintf
(
"Unexpected short copy: %v"
,
n
))
}
return
}
samples/flushfs/flush_fs_test.go
View file @
0698d680
...
...
@@ -75,6 +75,9 @@ func (t *FlushFSTest) SetUp(ti *TestInfo) {
// Helpers
////////////////////////////////////////////////////////////////////////
// Match byte slices equal to the supplied string.
func
byteSliceEq
(
expected
string
)
Matcher
// Return a copy of the current contents of t.flushes.
//
// LOCKS_EXCLUDED(t.mu)
...
...
@@ -127,11 +130,11 @@ func (t *FlushFSTest) CloseReports_ReadWrite() {
// Seek and read them back.
off
,
err
=
f
.
Seek
(
0
,
0
)
AssertEq
(
nil
,
err
)
AssertEq
(
4
,
off
)
AssertEq
(
0
,
off
)
n
,
err
=
f
.
Read
(
buf
)
AssertThat
(
err
,
AnyOf
(
nil
,
io
.
EOF
))
AssertEq
(
"taco"
,
buf
[
:
n
]
)
AssertEq
(
"taco"
,
string
(
buf
[
:
n
])
)
// At this point, no flushes or fsyncs should have happened.
AssertThat
(
t
.
getFlushes
(),
ElementsAre
())
...
...
@@ -143,7 +146,7 @@ func (t *FlushFSTest) CloseReports_ReadWrite() {
AssertEq
(
nil
,
err
)
// Now we should have received the flush operation (but still no fsync).
ExpectThat
(
t
.
getFlushes
(),
ElementsAre
(
"taco"
))
ExpectThat
(
t
.
getFlushes
(),
ElementsAre
(
byteSliceEq
(
"taco"
)
))
ExpectThat
(
t
.
getFsyncs
(),
ElementsAre
())
}
...
...
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