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
5a7e50da
Commit
5a7e50da
authored
Mar 24, 2015
by
Aaron Jacobs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use a helper to be more sure that temp files are cleaned up at exit.
parent
b5e00243
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
13 deletions
+57
-13
fsutil/fsutil.go
fsutil/fsutil.go
+50
-0
samples/flushfs/flush_fs_test.go
samples/flushfs/flush_fs_test.go
+7
-13
No files found.
fsutil/fsutil.go
0 → 100644
View file @
5a7e50da
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
fsutil
import
(
"fmt"
"io/ioutil"
"os"
"path"
)
// Create a temporary file with the same semantics as ioutil.TempFile, but
// ensure that it is unlinked before returning so that it does not persist
// after the process exits.
//
// Warning: this is not production-quality code, and should only be used for
// testing purposes. In particular, there is a race between creating and
// unlinking by name.
func
AnonymousFile
(
dir
string
)
(
f
*
os
.
File
,
err
error
)
{
// Choose a prefix based on the binary name.
prefix
:=
path
.
Base
(
os
.
Args
[
0
])
// Create the file.
f
,
err
=
ioutil
.
TempFile
(
dir
,
prefix
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"TempFile: %v"
,
err
)
return
}
// Unlink it.
err
=
os
.
Remove
(
f
.
Name
())
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Remove: %v"
,
err
)
return
}
return
}
samples/flushfs/flush_fs_test.go
View file @
5a7e50da
...
@@ -19,7 +19,6 @@ import (
...
@@ -19,7 +19,6 @@ import (
"encoding/hex"
"encoding/hex"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"os"
"os"
"path"
"path"
"runtime"
"runtime"
...
@@ -27,6 +26,7 @@ import (
...
@@ -27,6 +26,7 @@ import (
"testing"
"testing"
"github.com/jacobsa/bazilfuse"
"github.com/jacobsa/bazilfuse"
"github.com/jacobsa/fuse/fsutil"
"github.com/jacobsa/fuse/samples"
"github.com/jacobsa/fuse/samples"
.
"github.com/jacobsa/oglematchers"
.
"github.com/jacobsa/oglematchers"
.
"github.com/jacobsa/ogletest"
.
"github.com/jacobsa/ogletest"
...
@@ -57,10 +57,10 @@ func (t *flushFSTest) setUp(
...
@@ -57,10 +57,10 @@ func (t *flushFSTest) setUp(
var
err
error
var
err
error
// Set up files to receive flush and fsync reports.
// Set up files to receive flush and fsync reports.
t
.
flushes
,
err
=
ioutil
.
TempFile
(
""
,
""
)
t
.
flushes
,
err
=
fsutil
.
AnonymousFile
(
""
)
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
t
.
fsyncs
,
err
=
ioutil
.
TempFile
(
""
,
""
)
t
.
fsyncs
,
err
=
fsutil
.
AnonymousFile
(
""
)
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
// Set up test config.
// Set up test config.
...
@@ -486,11 +486,8 @@ func (t *NoErrorsTest) Dup2() {
...
@@ -486,11 +486,8 @@ func (t *NoErrorsTest) Dup2() {
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
AssertEq
(
4
,
n
)
AssertEq
(
4
,
n
)
// Open and unlink some temporary file.
// Create some anonymous temporary file.
t
.
f2
,
err
=
ioutil
.
TempFile
(
""
,
""
)
t
.
f2
,
err
=
fsutil
.
AnonymousFile
(
""
)
AssertEq
(
nil
,
err
)
err
=
os
.
Remove
(
t
.
f2
.
Name
())
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
// Duplicate the temporary file descriptor on top of the file from our file
// Duplicate the temporary file descriptor on top of the file from our file
...
@@ -693,11 +690,8 @@ func (t *FlushErrorTest) Dup2() {
...
@@ -693,11 +690,8 @@ func (t *FlushErrorTest) Dup2() {
t
.
f1
,
err
=
os
.
OpenFile
(
path
.
Join
(
t
.
Dir
,
"foo"
),
os
.
O_WRONLY
,
0
)
t
.
f1
,
err
=
os
.
OpenFile
(
path
.
Join
(
t
.
Dir
,
"foo"
),
os
.
O_WRONLY
,
0
)
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
// Open and unlink some temporary file.
// Create some anonymous temporary file.
t
.
f2
,
err
=
ioutil
.
TempFile
(
""
,
""
)
t
.
f2
,
err
=
fsutil
.
AnonymousFile
(
""
)
AssertEq
(
nil
,
err
)
err
=
os
.
Remove
(
t
.
f2
.
Name
())
AssertEq
(
nil
,
err
)
AssertEq
(
nil
,
err
)
// Duplicate the temporary file descriptor on top of the file from our file
// Duplicate the temporary file descriptor on top of the file from our file
...
...
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