mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-17 15:55:26 +01:00
Merge pull request #4307 from reasonerjt/vol-empty-path
Return zero instead of error if the volume directory is not found at …
This commit is contained in:
commit
78492a9d64
@ -15,9 +15,11 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
storage "github.com/vmware/harbor/src/adminserver/systeminfo/imagestorage"
|
||||
"github.com/vmware/harbor/src/common/utils/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -43,6 +45,12 @@ func (d *driver) Name() string {
|
||||
// Cap returns the capacity of the filesystem storage
|
||||
func (d *driver) Cap() (*storage.Capacity, error) {
|
||||
var stat syscall.Statfs_t
|
||||
if _, err := os.Stat(d.path); os.IsNotExist(err) {
|
||||
// Return zero value if the path does not exist.
|
||||
log.Warningf("The path %s is not found, will return zero value of capacity", d.path)
|
||||
return &storage.Capacity{Total: 0, Free: 0}, nil
|
||||
}
|
||||
|
||||
err := syscall.Statfs(d.path, &stat)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
storage "github.com/vmware/harbor/src/adminserver/systeminfo/imagestorage"
|
||||
)
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
@ -32,3 +33,11 @@ func TestCap(t *testing.T) {
|
||||
_, err := driver.Cap()
|
||||
assert.Nil(t, err, "unexpected error")
|
||||
}
|
||||
|
||||
func TestCapNonExistPath(t *testing.T) {
|
||||
path := "/not/exist"
|
||||
driver := NewDriver(path)
|
||||
c, err := driver.Cap()
|
||||
assert.Nil(t, err, "unexpected error")
|
||||
assert.Equal(t, storage.Capacity{0, 0}, *c)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user