Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ jobs:

- name: Goroutine leak detector
run: go test -c -o tests && for test in $(go test -list . | grep -E "^(Test|Example)"); do ./tests -test.run "^$test\$" &>/dev/null && echo -e "$test passed\n" || echo -e "$test failed\n"; done

- name: Build for Windows
continue-on-error: true
run: GOOS=windows GOARCH=amd64 go build -v ./...
14 changes: 0 additions & 14 deletions internal/pkg/controler/watchers/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"context"
"fmt"
"sync"
"syscall"
"time"

"github.com/internetarchive/Zeno/internal/pkg/config"
"github.com/internetarchive/Zeno/internal/pkg/controler/pause"
"github.com/internetarchive/Zeno/internal/pkg/log"
)
Expand Down Expand Up @@ -42,18 +40,6 @@ func checkThreshold(total, free uint64, minSpaceRequired float64) error {
return nil
}

func CheckDiskUsage(path string) error {
var stat syscall.Statfs_t
if err := syscall.Statfs(path, &stat); err != nil {
panic(fmt.Sprintf("Error retrieving disk stats: %v\n", err))
}

total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bavail * uint64(stat.Bsize)

return checkThreshold(total, free, config.Get().MinSpaceRequired)
}

// WatchDiskSpace watches the disk space and pauses the pipeline if it's low
func WatchDiskSpace(path string, interval time.Duration) {
diskWatcherWg.Add(1)
Expand Down
22 changes: 22 additions & 0 deletions internal/pkg/controler/watchers/disk_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !windows

package watchers

import (
"fmt"
"syscall"

"github.com/internetarchive/Zeno/internal/pkg/config"
)

func CheckDiskUsage(path string) error {
var stat syscall.Statfs_t
if err := syscall.Statfs(path, &stat); err != nil {
panic(fmt.Sprintf("Error retrieving disk stats: %v\n", err))
}

total := stat.Blocks * uint64(stat.Bsize)
free := stat.Bavail * uint64(stat.Bsize)

return checkThreshold(total, free, config.Get().MinSpaceRequired)
}
20 changes: 20 additions & 0 deletions internal/pkg/controler/watchers/disk_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build windows

package watchers

import (
"fmt"

"github.com/internetarchive/Zeno/internal/pkg/config"
"golang.org/x/sys/windows"
)

func CheckDiskUsage(path string) error {
var freeBytesAvailable uint64
var totalNumberOfBytes uint64
var totalNumberOfFreeBytes uint64
if err := windows.GetDiskFreeSpaceEx(windows.StringToUTF16Ptr(path), &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes); err != nil {
panic(fmt.Sprintf("Error retrieving disk stats: %v\n", err))
}
return checkThreshold(totalNumberOfBytes, freeBytesAvailable, config.Get().MinSpaceRequired)
}