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
Kirill Smelkov
go-fuse
Commits
815666ab
Commit
815666ab
authored
Sep 24, 2018
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fuse/test: clarify umask semantics
Improve test to eliminate backing FS semantics
parent
1d35017e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
31 deletions
+105
-31
fuse/test/loopback_test.go
fuse/test/loopback_test.go
+1
-27
fuse/test/umask_test.go
fuse/test/umask_test.go
+91
-0
fuse/types.go
fuse/types.go
+3
-0
fuse/types_linux.go
fuse/types_linux.go
+10
-4
No files found.
fuse/test/loopback_test.go
View file @
815666ab
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"io/ioutil"
"io/ioutil"
"math/rand"
"math/rand"
"os"
"os"
"os/exec"
"path/filepath"
"path/filepath"
"reflect"
"reflect"
"runtime"
"runtime"
...
@@ -25,8 +24,6 @@ import (
...
@@ -25,8 +24,6 @@ import (
"github.com/hanwen/go-fuse/internal/testutil"
"github.com/hanwen/go-fuse/internal/testutil"
)
)
const
mode
uint32
=
0757
type
testCase
struct
{
type
testCase
struct
{
tmpDir
string
tmpDir
string
orig
string
orig
string
...
@@ -148,6 +145,7 @@ func TestReadThrough(t *testing.T) {
...
@@ -148,6 +145,7 @@ func TestReadThrough(t *testing.T) {
content
:=
randomData
(
125
)
content
:=
randomData
(
125
)
tc
.
WriteFile
(
tc
.
origFile
,
content
,
0700
)
tc
.
WriteFile
(
tc
.
origFile
,
content
,
0700
)
var
mode
uint32
=
0757
err
:=
os
.
Chmod
(
tc
.
mountFile
,
os
.
FileMode
(
mode
))
err
:=
os
.
Chmod
(
tc
.
mountFile
,
os
.
FileMode
(
mode
))
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Chmod failed: %v"
,
err
)
t
.
Fatalf
(
"Chmod failed: %v"
,
err
)
...
@@ -916,31 +914,7 @@ func TestDoubleOpen(t *testing.T) {
...
@@ -916,31 +914,7 @@ func TestDoubleOpen(t *testing.T) {
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
t
.
Fatalf
(
"OpenFile failed: %v"
,
err
)
}
}
defer
rwFile
.
Close
()
defer
rwFile
.
Close
()
}
func
TestUmask
(
t
*
testing
.
T
)
{
tc
:=
NewTestCase
(
t
)
defer
tc
.
Cleanup
()
// Make sure system setting does not affect test.
fn
:=
tc
.
mnt
+
"/file"
mask
:=
020
cmd
:=
exec
.
Command
(
"/bin/sh"
,
"-c"
,
fmt
.
Sprintf
(
"umask %o && mkdir %s"
,
mask
,
fn
))
if
err
:=
cmd
.
Run
();
err
!=
nil
{
t
.
Fatalf
(
"cmd.Run: %v"
,
err
)
}
fi
,
err
:=
os
.
Lstat
(
fn
)
if
err
!=
nil
{
t
.
Fatalf
(
"Lstat failed: %v"
,
err
)
}
expect
:=
mask
^
0777
got
:=
int
(
fi
.
Mode
()
.
Perm
())
if
got
!=
expect
{
t
.
Errorf
(
"got %o, expect mode %o for file %s"
,
got
,
expect
,
fn
)
}
}
}
// Check that chgrp(1) works
// Check that chgrp(1) works
...
...
fuse/test/umask_test.go
0 → 100644
View file @
815666ab
// Copyright 2016 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
test
import
(
"fmt"
"os"
"os/exec"
"testing"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/fuse/nodefs"
"github.com/hanwen/go-fuse/fuse/pathfs"
"github.com/hanwen/go-fuse/internal/testutil"
)
type
umaskFS
struct
{
pathfs
.
FileSystem
mkdirMode
uint32
createMode
uint32
}
func
(
fs
*
umaskFS
)
Create
(
name
string
,
flags
uint32
,
mode
uint32
,
context
*
fuse
.
Context
)
(
file
nodefs
.
File
,
code
fuse
.
Status
)
{
fs
.
createMode
=
mode
return
fs
.
FileSystem
.
Create
(
name
,
flags
,
mode
,
context
)
}
func
(
fs
*
umaskFS
)
Mkdir
(
name
string
,
mode
uint32
,
context
*
fuse
.
Context
)
(
code
fuse
.
Status
)
{
fs
.
mkdirMode
=
mode
return
fs
.
FileSystem
.
Mkdir
(
name
,
mode
,
context
)
}
func
TestUmask
(
t
*
testing
.
T
)
{
tmpDir
:=
testutil
.
TempDir
()
orig
:=
tmpDir
+
"/orig"
mnt
:=
tmpDir
+
"/mnt"
os
.
Mkdir
(
orig
,
0700
)
os
.
Mkdir
(
mnt
,
0700
)
var
pfs
pathfs
.
FileSystem
pfs
=
pathfs
.
NewLoopbackFileSystem
(
orig
)
pfs
=
pathfs
.
NewLockingFileSystem
(
pfs
)
ufs
:=
&
umaskFS
{
FileSystem
:
pfs
}
pathFs
:=
pathfs
.
NewPathNodeFs
(
ufs
,
&
pathfs
.
PathNodeFsOptions
{
ClientInodes
:
true
})
connector
:=
nodefs
.
NewFileSystemConnector
(
pathFs
.
Root
(),
&
nodefs
.
Options
{
EntryTimeout
:
testTtl
,
AttrTimeout
:
testTtl
,
NegativeTimeout
:
0.0
,
Debug
:
testutil
.
VerboseTest
(),
LookupKnownChildren
:
true
,
})
server
,
err
:=
fuse
.
NewServer
(
fuse
.
NewRawFileSystem
(
connector
.
RawFS
()),
mnt
,
&
fuse
.
MountOptions
{
SingleThreaded
:
true
,
Debug
:
testutil
.
VerboseTest
(),
})
if
err
!=
nil
{
t
.
Fatal
(
"NewServer:"
,
err
)
}
go
server
.
Serve
()
if
err
:=
server
.
WaitMount
();
err
!=
nil
{
t
.
Fatal
(
"WaitMount"
,
err
)
}
// Make sure system setting does not affect test.
mask
:=
020
cmd
:=
exec
.
Command
(
"/bin/sh"
,
"-c"
,
fmt
.
Sprintf
(
"umask %o && cd %s && mkdir x && touch y"
,
mask
,
mnt
))
if
err
:=
cmd
.
Run
();
err
!=
nil
{
t
.
Fatalf
(
"cmd.Run: %v"
,
err
)
}
if
err
:=
server
.
Unmount
();
err
!=
nil
{
t
.
Fatalf
(
"Unmount %v"
,
err
)
}
if
got
,
want
:=
ufs
.
mkdirMode
&
0777
,
uint32
(
0757
);
got
!=
want
{
t
.
Errorf
(
"got dirMode %o want %o"
,
got
,
want
)
}
if
got
,
want
:=
ufs
.
createMode
&
0666
,
uint32
(
0646
);
got
!=
want
{
t
.
Errorf
(
"got createMode %o want %o"
,
got
,
want
)
}
}
fuse/types.go
View file @
815666ab
...
@@ -86,6 +86,9 @@ type _BatchForgetIn struct {
...
@@ -86,6 +86,9 @@ type _BatchForgetIn struct {
type
MkdirIn
struct
{
type
MkdirIn
struct
{
InHeader
InHeader
// The mode for the new directory. The calling process' umask
// is already factored into the mode.
Mode
uint32
Mode
uint32
Umask
uint32
Umask
uint32
}
}
...
...
fuse/types_linux.go
View file @
815666ab
...
@@ -62,13 +62,19 @@ func (g *GetAttrIn) Fh() uint64 {
...
@@ -62,13 +62,19 @@ func (g *GetAttrIn) Fh() uint64 {
type
CreateIn
struct
{
type
CreateIn
struct
{
InHeader
InHeader
Flags
uint32
Flags
uint32
// Mode for the new file; already takes Umask into account.
Mode
uint32
Mode
uint32
// Umask used for this create call.
Umask
uint32
Umask
uint32
Pading
uint32
Pad
d
ing
uint32
}
}
type
MknodIn
struct
{
type
MknodIn
struct
{
InHeader
InHeader
// Mode to use, including the Umask value
Mode
uint32
Mode
uint32
Rdev
uint32
Rdev
uint32
Umask
uint32
Umask
uint32
...
...
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