Skip to content

Commit

Permalink
Merge pull request #195 from rstudio/jon-win
Browse files Browse the repository at this point in the history
Windows support
  • Loading branch information
jonyoder authored Aug 23, 2024
2 parents 61c2cc3 + dae6157 commit 133c615
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions pkg/rsstorage/servers/file/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"log/slog"
"os"
"path/filepath"
"syscall"
"time"

"github.com/c2h5oh/datasize"
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions pkg/rsstorage/servers/file/server_unix.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions pkg/rsstorage/servers/file/server_windows.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 133c615

Please sign in to comment.