Skip to content

Commit a0ca0d8

Browse files
committed
SyncCapability is not a DefaultCapability
1 parent 516fc7a commit a0ca0d8

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

fs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
// major version is released.
4343
DefaultCapabilities Capability = WriteCapability | ReadCapability |
4444
ReadAndWriteCapability | SeekCapability | TruncateCapability |
45-
LockCapability | SyncCapability
45+
LockCapability
4646

4747
// AllCapabilities lists all capable features.
4848
AllCapabilities Capability = WriteCapability | ReadCapability |
@@ -184,7 +184,7 @@ type File interface {
184184

185185
// Syncer interface can be implemented by filesystems that support syncing.
186186
type Syncer interface {
187-
// Commit the current contents of the file to stable storage.
187+
// Sync commits the current contents of the file to stable storage.
188188
Sync() error
189189
}
190190

memfs/memory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestCapabilities(t *testing.T) {
3131
assert.True(t, ok)
3232

3333
caps := billy.Capabilities(fs)
34-
assert.Equal(t, billy.DefaultCapabilities&^billy.LockCapability&^billy.SyncCapability, caps)
34+
assert.Equal(t, billy.DefaultCapabilities&^billy.LockCapability, caps)
3535
}
3636

3737
func TestModTime(t *testing.T) {

osfs/os_bound.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func newBoundOS(d string, deduplicatePath bool) billy.Filesystem {
5454
return &BoundOS{baseDir: d, deduplicatePath: deduplicatePath}
5555
}
5656

57+
func (fs *BoundOS) Capabilities() billy.Capability {
58+
return billy.DefaultCapabilities & billy.SyncCapability
59+
}
60+
5761
func (fs *BoundOS) Create(filename string) (billy.File, error) {
5862
return fs.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, defaultCreateMode)
5963
}

osfs/os_bound_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ import (
3232
"github.com/stretchr/testify/require"
3333
)
3434

35+
func TestBoundOSCapabilities(t *testing.T) {
36+
dir := t.TempDir()
37+
fs := newBoundOS(dir, true)
38+
_, ok := fs.(billy.Capable)
39+
assert.True(t, ok)
40+
41+
caps := billy.Capabilities(fs)
42+
assert.Equal(t, billy.DefaultCapabilities&billy.SyncCapability, caps)
43+
}
44+
3545
func TestOpen(t *testing.T) {
3646
tests := []struct {
3747
name string

osfs/os_chroot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ func TestCapabilities(t *testing.T) {
4545
assert.True(t, ok)
4646

4747
caps := billy.Capabilities(fs)
48-
assert.Equal(t, billy.AllCapabilities, caps)
48+
assert.Equal(t, billy.DefaultCapabilities, caps)
4949
}

util/util.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ func WriteFile(fs billy.Basic, filename string, data []byte, perm fs.FileMode) (
117117
err = io.ErrShortWrite
118118
}
119119
if sf, ok := f.(billy.Syncer); ok {
120-
err = sf.Sync()
121-
if err != nil {
122-
return err
123-
}
120+
return sf.Sync()
124121
}
125122

126123
return nil

0 commit comments

Comments
 (0)