Skip to content

Commit 5bb98d7

Browse files
committed
Rename capability names to <name>Capability
Signed-off-by: Javi Fontan <[email protected]>
1 parent e2ca534 commit 5bb98d7

File tree

6 files changed

+42
-40
lines changed

6 files changed

+42
-40
lines changed

fs.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,35 @@ var (
1515

1616
// Capability holds the supported features of a billy filesystem. This does
1717
// 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.
18+
// For example, a billy filesystem may support WriteCapability but the
19+
// storage be mounted in read only mode.
2020
type Capability uint64
2121

2222
const (
23-
// CapWrite means that the fs is writable.
24-
CapWrite Capability = 1 << iota
25-
// CapRead means that the fs is readable.
26-
CapRead
27-
// CapReadAndWrite is the ability to open a file in read and write mode.
28-
CapReadAndWrite
29-
// CapSeek means it is able to move position inside the file.
30-
CapSeek
31-
// CapTruncate means that a file can be truncated.
32-
CapTruncate
33-
// CapLock is the ability to lock a file.
34-
CapLock
35-
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-
42-
// CapAll lists all capable features.
43-
CapAll Capability = CapWrite | CapRead | CapReadAndWrite |
44-
CapSeek | CapTruncate | CapLock
23+
// WriteCapability means that the fs is writable.
24+
WriteCapability Capability = 1 << iota
25+
// ReadCapability means that the fs is readable.
26+
ReadCapability
27+
// ReadAndWriteCapability is the ability to open a file in read and write mode.
28+
ReadAndWriteCapability
29+
// SeekCapability means it is able to move position inside the file.
30+
SeekCapability
31+
// TruncateCapability means that a file can be truncated.
32+
TruncateCapability
33+
// LockCapability is the ability to lock a file.
34+
LockCapability
35+
36+
// DefaultCapabilities lists all capable features supported by filesystems
37+
// without Capability interface. This list should not be changed until a
38+
// major version is released.
39+
DefaultCapabilities Capability = WriteCapability | ReadCapability |
40+
ReadAndWriteCapability | SeekCapability | TruncateCapability |
41+
LockCapability
42+
43+
// AllCapabilities lists all capable features.
44+
AllCapabilities Capability = WriteCapability | ReadCapability |
45+
ReadAndWriteCapability | SeekCapability | TruncateCapability |
46+
LockCapability
4547
)
4648

4749
// Filesystem abstract the operations in a storage-agnostic interface.
@@ -186,7 +188,7 @@ type Capable interface {
186188
func Capabilities(fs Basic) Capability {
187189
capable, ok := fs.(Capable)
188190
if !ok {
189-
return CapDefault
191+
return DefaultCapabilities
190192
}
191193

192194
return capable.Capabilities()

fs_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ func (s *FSSuite) TestCapabilities(c *C) {
2020
caps Capability
2121
expected bool
2222
}{
23-
{CapLock, false},
24-
{CapRead, true},
25-
{CapRead | CapWrite, true},
26-
{CapRead | CapWrite | CapReadAndWrite | CapTruncate, true},
27-
{CapRead | CapWrite | CapReadAndWrite | CapTruncate | CapLock, false},
28-
{CapTruncate | CapLock, false},
23+
{LockCapability, false},
24+
{ReadCapability, true},
25+
{ReadCapability | WriteCapability, true},
26+
{ReadCapability | WriteCapability | ReadAndWriteCapability | TruncateCapability, true},
27+
{ReadCapability | WriteCapability | ReadAndWriteCapability | TruncateCapability | LockCapability, false},
28+
{TruncateCapability | LockCapability, false},
2929
}
3030

31-
// This filesystem supports all capabilities except for CapLock
31+
// This filesystem supports all capabilities except for LockCapability
3232
mem := memfs.New()
3333

3434
for _, e := range cases {

memfs/memory.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ func (fs *Memory) Readlink(link string) (string, error) {
192192

193193
// Capabilities implements the Capable interface.
194194
func (fs *Memory) Capabilities() billy.Capability {
195-
return billy.CapWrite |
196-
billy.CapRead |
197-
billy.CapReadAndWrite |
198-
billy.CapSeek |
199-
billy.CapTruncate
195+
return billy.WriteCapability |
196+
billy.ReadCapability |
197+
billy.ReadAndWriteCapability |
198+
billy.SeekCapability |
199+
billy.TruncateCapability
200200
}
201201

202202
type file struct {

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.CapDefault&^billy.CapLock)
30+
c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability)
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.CapDefault
132+
return billy.DefaultCapabilities
133133
}
134134

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

osfs/os_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ func (s *OSSuite) TestCapabilities(c *C) {
4444
c.Assert(ok, Equals, true)
4545

4646
caps := billy.Capabilities(s.FS)
47-
c.Assert(caps, Equals, billy.CapAll)
47+
c.Assert(caps, Equals, billy.AllCapabilities)
4848
}

0 commit comments

Comments
 (0)