Skip to content

Commit 5fbe854

Browse files
Fix tests for windows, fix umask parsing
1 parent 9bdd53b commit 5fbe854

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

cmd/mount.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ var mountCmd = &cobra.Command{
416416
options.NonEmpty = true
417417
config.Set("nonempty", "true")
418418
} else if hasEq && key == "umask" {
419-
umask, err := strconv.ParseUint(val, 10, 32)
419+
umask, err := parseUmaskOption(val)
420420
if err != nil {
421-
return fmt.Errorf("failed to parse umask [%s]", err.Error())
421+
return err
422422
}
423423
config.Set("lfuse.umask", fmt.Sprint(umask))
424424
} else if hasEq && key == "uid" {
@@ -678,6 +678,17 @@ func ignoreFuseOptions(opt string) bool {
678678
return false
679679
}
680680

681+
func parseUmaskOption(raw string) (uint32, error) {
682+
umask, err := strconv.ParseUint(raw, 8, 32)
683+
if err != nil {
684+
return 0, fmt.Errorf("failed to parse umask [%s]", err.Error())
685+
}
686+
if umask > 0o777 {
687+
return 0, fmt.Errorf("failed to parse umask [value out of range: %s]", raw)
688+
}
689+
return uint32(umask), nil
690+
}
691+
681692
func runPipeline(pipeline *internal.Pipeline, ctx context.Context) error {
682693
pid := fmt.Sprintf("%v", os.Getpid())
683694
common.TransferPipe += "_" + pid

component/libfuse/fuse2_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func createFuseOptions(
6969
options += ",atomic_o_trunc"
7070

7171
if umask != 0 {
72-
options += fmt.Sprintf(",umask=%04d", umask)
72+
options += fmt.Sprintf(",umask=%04o", umask)
7373
}
7474

7575
// direct_io option is used to bypass the kernel cache. It disables the use of

component/libfuse/fuse3_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func createFuseOptions(
6464
}
6565

6666
if umask != 0 {
67-
options += fmt.Sprintf(",umask=%04d", umask)
67+
options += fmt.Sprintf(",umask=%04o", umask)
6868
}
6969

7070
// direct_io option is used to bypass the kernel cache. It disables the use of

component/libfuse/libfuse2_handler_test_wrapper.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ func testMkDirErrorPermission(suite *libfuseTestSuite) {
243243
path := "/" + name
244244
mode := fs.FileMode(0775)
245245
options := internal.CreateDirOptions{Name: name, Mode: mode}
246+
247+
if runtime.GOOS == "windows" {
248+
option := internal.GetAttrOptions{Name: name}
249+
suite.mock.EXPECT().GetAttr(option).Return(nil, syscall.ENOENT)
250+
}
251+
246252
suite.mock.EXPECT().CreateDir(options).Return(os.ErrPermission)
247253

248254
err := cfuseFS.Mkdir(path, 0775)
@@ -255,6 +261,12 @@ func testMkDirErrorExist(suite *libfuseTestSuite) {
255261
path := "/" + name
256262
mode := fs.FileMode(0775)
257263
options := internal.CreateDirOptions{Name: name, Mode: mode}
264+
265+
if runtime.GOOS == "windows" {
266+
option := internal.GetAttrOptions{Name: name}
267+
suite.mock.EXPECT().GetAttr(option).Return(nil, syscall.ENOENT)
268+
}
269+
258270
suite.mock.EXPECT().CreateDir(options).Return(os.ErrExist)
259271

260272
err := cfuseFS.Mkdir(path, 0775)
@@ -490,7 +502,7 @@ func testReadFromComponent(suite *libfuseTestSuite) {
490502
suite.assert.Equal(handle.ID, opt.Handle.ID)
491503
suite.assert.Equal("file", opt.Handle.Path)
492504
suite.assert.Equal(int64(7), opt.Offset)
493-
suite.assert.Equal(4, len(opt.Data))
505+
suite.assert.Len(opt.Data, 4)
494506
copy(opt.Data, []byte("ping"))
495507
return 4, nil
496508
})
@@ -511,7 +523,7 @@ func testReadAccessDenied(suite *libfuseTestSuite) {
511523
DoAndReturn(func(opt *internal.ReadInBufferOptions) (int, error) {
512524
suite.assert.Equal(handle.ID, opt.Handle.ID)
513525
suite.assert.Equal(int64(3), opt.Offset)
514-
suite.assert.Equal(4, len(opt.Data))
526+
suite.assert.Len(opt.Data, 4)
515527
return 0, os.ErrPermission
516528
})
517529
read := cfuseFS.Read("/file", buf, 3, uint64(fh))
@@ -530,7 +542,7 @@ func testReadError(suite *libfuseTestSuite) {
530542
DoAndReturn(func(opt *internal.ReadInBufferOptions) (int, error) {
531543
suite.assert.Equal(handle.ID, opt.Handle.ID)
532544
suite.assert.Equal(int64(5), opt.Offset)
533-
suite.assert.Equal(4, len(opt.Data))
545+
suite.assert.Len(opt.Data, 4)
534546
return 0, errors.New("boom")
535547
})
536548
read := cfuseFS.Read("/file", buf, 5, uint64(fh))
@@ -776,7 +788,7 @@ func testCreateFuseOptionsFlags(suite *libfuseTestSuite) {
776788
if !strings.Contains(options, "ro") {
777789
suite.T().Fatal("expected ro in options")
778790
}
779-
expectedUmask := fmt.Sprintf("umask=%04d", umask)
791+
expectedUmask := fmt.Sprintf("umask=%04o", umask)
780792
if !strings.Contains(options, expectedUmask) {
781793
suite.T().Fatal("expected umask in options")
782794
}
@@ -791,6 +803,9 @@ func testCreateFuseOptionsDirectIO(suite *libfuseTestSuite) {
791803
fuseFS.directIO = true
792804

793805
options := createFuseOptions(host, false, false, false, false, 128, 0)
806+
if !strings.Contains(options, "direct_io") {
807+
suite.T().Fatal("expected direct_io in direct-io options")
808+
}
794809
if strings.Contains(options, "kernel_cache") {
795810
suite.T().Fatal("did not expect kernel_cache in direct-io options")
796811
}

component/libfuse/libfuse_handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ func (suite *libfuseTestSuite) TestConfigDefaultPermission() {
188188
func (suite *libfuseTestSuite) TestConfigRootAndThreads() {
189189
defer suite.cleanupTest()
190190
suite.cleanupTest()
191-
config := "allow-root: true\nnonempty: true\nlibfuse:\n max-fuse-threads: 256\n umask: 22\n uid: 1001\n gid: 1002\n"
191+
config := "allow-root: true\nnonempty: true\nlibfuse:\n max-fuse-threads: 256\n umask: 022\n uid: 1001\n gid: 1002\n"
192192
suite.setupTestHelper(config)
193193

194194
suite.assert.True(suite.libfuse.allowRoot)
195195
suite.assert.True(suite.libfuse.nonEmptyMount)
196196
suite.assert.Equal(uint32(256), suite.libfuse.maxFuseThreads)
197-
suite.assert.Equal(uint32(22), suite.libfuse.umask)
197+
suite.assert.Equal(uint32(0o22), suite.libfuse.umask)
198198
suite.assert.Equal(uint32(1001), suite.libfuse.ownerUID)
199199
suite.assert.Equal(uint32(1002), suite.libfuse.ownerGID)
200200
}

setup/advancedConfig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ libfuse:
7878
disable-writeback-cache: true|false <disallow libfuse to buffer write requests if you must strictly open files in O_WRONLY or O_APPEND mode. alternatively, you can set ignore-open-flags.>
7979
ignore-open-flags: true|false <ignore the append and write only flag since O_APPEND and O_WRONLY is not supported with writeback caching. alternatively, you can disable-writeback-cache. Default value is true>
8080
max-fuse-threads: <number of threads allowed at libfuse layer for highly parallel operations, Default is 128>
81+
umask: <FUSE mount permission mask in octal. Ex. 022 -> files 0644 and directories 0755.>
8182
direct-io: true|false <enable to bypass the kernel cache. It also disables cloudfuse data and metadata caching.>
8283
network-share: true|false <runs as a network share. may improve performance when latency to cloud is high. only supported on Windows. Known issue - only one Cloudfuse network share can be mounted at a time>
8384
display-capacity-mb: <number of MB to display as the mounted storage capacity. Default - 1PB (1073741824 MB)>

setup/baseConfig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ libfuse:
7171
disable-writeback-cache: true|false <disallow libfuse to buffer write requests if you must strictly open files in O_WRONLY or O_APPEND mode. alternatively, you can set ignore-open-flags.>
7272
ignore-open-flags: true|false <ignore the append and write only flag since O_APPEND and O_WRONLY is not supported with writeback caching. alternatively, you can disable-writeback-cache. Default value is true>
7373
max-fuse-threads: <number of threads allowed at libfuse layer for highly parallel operations, Default is 128>
74+
umask: <FUSE mount permission mask in octal. Ex. 022 -> files 0644 and directories 0755.>
7475
direct-io: true|false <enable to bypass the kernel cache>
7576
network-share: true|false <runs as a network share. may improve performance when latency to cloud is high. only supported on Windows. Known issue - only one Cloudfuse network share can be mounted at a time>
7677
display-capacity-mb: <number of MB to display as the mounted storage capacity. Default - 1PB (1073741824 MB)>

0 commit comments

Comments
 (0)