Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
jonyoder committed Aug 23, 2024
1 parent 61c2cc3 commit ab5cb1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
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
23 changes: 23 additions & 0 deletions pkg/rsstorage/servers/file/server_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2024 by RStudio, PBC

//nolint:goheader // Go build directives confuse goheader
//go:build !windows

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 @@
// Copyright (C) 2024 by RStudio, PBC

package file

import "errors"

func Statfs(path string) (*StatfsData, error) {
return nil, errors.New("Statfs is not supported on Windows")
}

0 comments on commit ab5cb1b

Please sign in to comment.