diff --git a/justfile b/justfile index 1b903c9..2cc8636 100644 --- a/justfile +++ b/justfile @@ -28,7 +28,7 @@ test-integration *args: # use a randomized project name to allow simultaneous test runs project="platform-lib-it-$(openssl rand -hex 4)" - dc="docker-compose -f docker/docker-compose.test.yml -p ${project}" + dc="docker compose -f docker/docker-compose.test.yml -p ${project}" function cleanup() { ${dc} logs --no-color > test-integration-${project}.log diff --git a/pkg/rsstorage/servers/file/server.go b/pkg/rsstorage/servers/file/server.go index 552f8c7..bc26630 100644 --- a/pkg/rsstorage/servers/file/server.go +++ b/pkg/rsstorage/servers/file/server.go @@ -13,7 +13,6 @@ import ( "log/slog" "os" "path/filepath" - "syscall" "time" "github.com/c2h5oh/datasize" @@ -118,17 +117,22 @@ func (s *StorageServer) Type() types.StorageType { return rsstorage.StorageTypeFile } +type StatfsData struct { + Bfree uint64 + Bsize int64 + Blocks uint64 +} + func (s *StorageServer) CalculateUsage() (types.Usage, error) { start := time.Now() - fs := syscall.Statfs_t{} - err := syscall.Statfs(s.dir, &fs) + stat, err := Statfs(s.dir) if err != nil { return types.Usage{}, fmt.Errorf("error calculating filesystem capacity for %s: %s.\n", s.dir, err) } - all := fs.Blocks * uint64(fs.Bsize) - free := fs.Bfree * uint64(fs.Bsize) + all := stat.Blocks * uint64(stat.Bsize) + free := stat.Bfree * uint64(stat.Bsize) timeInfo := time.Now() elapsed := timeInfo.Sub(start) diff --git a/pkg/rsstorage/servers/file/server_unix.go b/pkg/rsstorage/servers/file/server_unix.go new file mode 100644 index 0000000..0827463 --- /dev/null +++ b/pkg/rsstorage/servers/file/server_unix.go @@ -0,0 +1,22 @@ +//go:build !windows + +// Copyright (C) 2024 by RStudio, PBC. + +package file + +import ( + "syscall" +) + +func Statfs(path string) (*StatfsData, error) { + fs := syscall.Statfs_t{} + err := syscall.Statfs(path, &fs) + if err != nil { + return nil, err + } + return &StatfsData{ + Bsize: fs.Bsize, + Blocks: fs.Blocks, + Bfree: fs.Bfree, + }, nil +} diff --git a/pkg/rsstorage/servers/file/server_windows.go b/pkg/rsstorage/servers/file/server_windows.go new file mode 100644 index 0000000..da40806 --- /dev/null +++ b/pkg/rsstorage/servers/file/server_windows.go @@ -0,0 +1,9 @@ +package file + +// Copyright (C) 2024 by RStudio, PBC. + +import "errors" + +func Statfs(path string) (*StatfsData, error) { + return nil, errors.New("Statfs is not supported on Windows") +}