Browse Source

Rename capability names to <name>Capability

Signed-off-by: Javi Fontan <jfontan@gmail.com>
tags/v4.2.0^2
Javi Fontan 1 year ago
parent
commit
5bb98d7916
6 changed files with 42 additions and 40 deletions
  1. 27
    25
      fs.go
  2. 7
    7
      fs_test.go
  3. 5
    5
      memfs/memory.go
  4. 1
    1
      memfs/memory_test.go
  5. 1
    1
      osfs/os.go
  6. 1
    1
      osfs/os_test.go

+ 27
- 25
fs.go View File

@@ -15,33 +15,35 @@ var (

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

const (
// CapWrite means that the fs is writable.
CapWrite Capability = 1 << iota
// CapRead means that the fs is readable.
CapRead
// CapReadAndWrite is the ability to open a file in read and write mode.
CapReadAndWrite
// CapSeek means it is able to move position inside the file.
CapSeek
// CapTruncate means that a file can be truncated.
CapTruncate
// CapLock is the ability to lock a file.
CapLock

// CapDefault lists all capable features supported by filesystems without
// Capability interface. This list should not be changed until a major
// version is released.
CapDefault Capability = CapWrite | CapRead | CapReadAndWrite |
CapSeek | CapTruncate | CapLock

// CapAll lists all capable features.
CapAll Capability = CapWrite | CapRead | CapReadAndWrite |
CapSeek | CapTruncate | CapLock
// WriteCapability means that the fs is writable.
WriteCapability Capability = 1 << iota
// ReadCapability means that the fs is readable.
ReadCapability
// ReadAndWriteCapability is the ability to open a file in read and write mode.
ReadAndWriteCapability
// SeekCapability means it is able to move position inside the file.
SeekCapability
// TruncateCapability means that a file can be truncated.
TruncateCapability
// LockCapability is the ability to lock a file.
LockCapability

// DefaultCapabilities lists all capable features supported by filesystems
// without Capability interface. This list should not be changed until a
// major version is released.
DefaultCapabilities Capability = WriteCapability | ReadCapability |
ReadAndWriteCapability | SeekCapability | TruncateCapability |
LockCapability

// AllCapabilities lists all capable features.
AllCapabilities Capability = WriteCapability | ReadCapability |
ReadAndWriteCapability | SeekCapability | TruncateCapability |
LockCapability
)

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

return capable.Capabilities()

+ 7
- 7
fs_test.go View File

@@ -20,15 +20,15 @@ func (s *FSSuite) TestCapabilities(c *C) {
caps Capability
expected bool
}{
{CapLock, false},
{CapRead, true},
{CapRead | CapWrite, true},
{CapRead | CapWrite | CapReadAndWrite | CapTruncate, true},
{CapRead | CapWrite | CapReadAndWrite | CapTruncate | CapLock, false},
{CapTruncate | CapLock, false},
{LockCapability, false},
{ReadCapability, true},
{ReadCapability | WriteCapability, true},
{ReadCapability | WriteCapability | ReadAndWriteCapability | TruncateCapability, true},
{ReadCapability | WriteCapability | ReadAndWriteCapability | TruncateCapability | LockCapability, false},
{TruncateCapability | LockCapability, false},
}

// This filesystem supports all capabilities except for CapLock
// This filesystem supports all capabilities except for LockCapability
mem := memfs.New()

for _, e := range cases {

+ 5
- 5
memfs/memory.go View File

@@ -192,11 +192,11 @@ func (fs *Memory) Readlink(link string) (string, error) {

// Capabilities implements the Capable interface.
func (fs *Memory) Capabilities() billy.Capability {
return billy.CapWrite |
billy.CapRead |
billy.CapReadAndWrite |
billy.CapSeek |
billy.CapTruncate
return billy.WriteCapability |
billy.ReadCapability |
billy.ReadAndWriteCapability |
billy.SeekCapability |
billy.TruncateCapability
}

type file struct {

+ 1
- 1
memfs/memory_test.go View File

@@ -27,5 +27,5 @@ func (s *MemorySuite) TestCapabilities(c *C) {
c.Assert(ok, Equals, true)

caps := billy.Capabilities(s.FS)
c.Assert(caps, Equals, billy.CapDefault&^billy.CapLock)
c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability)
}

+ 1
- 1
osfs/os.go View File

@@ -129,7 +129,7 @@ func (fs *OS) Readlink(link string) (string, error) {

// Capabilities implements the Capable interface.
func (fs *OS) Capabilities() billy.Capability {
return billy.CapDefault
return billy.DefaultCapabilities
}

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

+ 1
- 1
osfs/os_test.go View File

@@ -44,5 +44,5 @@ func (s *OSSuite) TestCapabilities(c *C) {
c.Assert(ok, Equals, true)

caps := billy.Capabilities(s.FS)
c.Assert(caps, Equals, billy.CapAll)
c.Assert(caps, Equals, billy.AllCapabilities)
}

Loading…
Cancel
Save