mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 12:15:20 +01:00
Return zero instead of error if the volume directory is not found at admin server
This commit is contained in:
parent
ae2f2dfc6d
commit
fc4e427c41
@ -15,9 +15,11 @@
|
|||||||
package filesystem
|
package filesystem
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
storage "github.com/vmware/harbor/src/adminserver/systeminfo/imagestorage"
|
storage "github.com/vmware/harbor/src/adminserver/systeminfo/imagestorage"
|
||||||
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -43,6 +45,12 @@ func (d *driver) Name() string {
|
|||||||
// Cap returns the capacity of the filesystem storage
|
// Cap returns the capacity of the filesystem storage
|
||||||
func (d *driver) Cap() (*storage.Capacity, error) {
|
func (d *driver) Cap() (*storage.Capacity, error) {
|
||||||
var stat syscall.Statfs_t
|
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)
|
err := syscall.Statfs(d.path, &stat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
storage "github.com/vmware/harbor/src/adminserver/systeminfo/imagestorage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
func TestName(t *testing.T) {
|
||||||
@ -32,3 +33,11 @@ func TestCap(t *testing.T) {
|
|||||||
_, err := driver.Cap()
|
_, err := driver.Cap()
|
||||||
assert.Nil(t, err, "unexpected error")
|
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