Skip to content

Commit e2ca534

Browse files
committed
More documentation and add CapDefault
CapDefault has all the capabilities supported in the current release and should not be changed until a new major release. Also changed Capabilities of mount to return the common capabilities from both filesystems. Signed-off-by: Javi Fontan <[email protected]>
1 parent d198577 commit e2ca534

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

fs.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ var (
1313
ErrCrossedBoundary = errors.New("chroot boundary crossed")
1414
)
1515

16-
// Capability holds the supported features of a filesystem.
16+
// Capability holds the supported features of a billy filesystem. This does
17+
// not mean that the capability has to be supported by the underlying storage.
18+
// For example, a billy filesystem may support CapWrite but the storage be
19+
// mounted in read only mode.
1720
type Capability uint64
1821

1922
const (
@@ -30,6 +33,12 @@ const (
3033
// CapLock is the ability to lock a file.
3134
CapLock
3235

36+
// CapDefault lists all capable features supported by filesystems without
37+
// Capability interface. This list should not be changed until a major
38+
// version is released.
39+
CapDefault Capability = CapWrite | CapRead | CapReadAndWrite |
40+
CapSeek | CapTruncate | CapLock
41+
3342
// CapAll lists all capable features.
3443
CapAll Capability = CapWrite | CapRead | CapReadAndWrite |
3544
CapSeek | CapTruncate | CapLock
@@ -177,7 +186,7 @@ type Capable interface {
177186
func Capabilities(fs Basic) Capability {
178187
capable, ok := fs.(Capable)
179188
if !ok {
180-
return CapAll
189+
return CapDefault
181190
}
182191

183192
return capable.Capabilities()

helper/mount/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (h *Mount) Underlying() billy.Basic {
169169

170170
// Capabilities implements the Capable interface.
171171
func (fs *Mount) Capabilities() billy.Capability {
172-
return billy.Capabilities(fs.underlying)
172+
return billy.Capabilities(fs.underlying) & billy.Capabilities(fs.source)
173173
}
174174

175175
func (fs *Mount) getBasicAndPath(path string) (billy.Basic, string) {

memfs/memory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ func (s *MemorySuite) TestCapabilities(c *C) {
2727
c.Assert(ok, Equals, true)
2828

2929
caps := billy.Capabilities(s.FS)
30-
c.Assert(caps, Equals, billy.CapAll&^billy.CapLock)
30+
c.Assert(caps, Equals, billy.CapDefault&^billy.CapLock)
3131
}

osfs/os.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (fs *OS) Readlink(link string) (string, error) {
129129

130130
// Capabilities implements the Capable interface.
131131
func (fs *OS) Capabilities() billy.Capability {
132-
return billy.CapAll
132+
return billy.CapDefault
133133
}
134134

135135
// file is a wrapper for an os.File which adds support for file locking.

0 commit comments

Comments
 (0)