Add standalone desktop workflow
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -59,30 +58,6 @@ func Probe(mountPath string) (DiskInfo, error) {
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func IsMountPoint(path string) bool {
|
||||
pathInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
parent := filepath.Dir(filepath.Clean(path))
|
||||
parentInfo, err := os.Stat(parent)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
pathStat, ok := pathInfo.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
parentStat, ok := parentInfo.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return pathStat.Dev != parentStat.Dev
|
||||
}
|
||||
|
||||
func CheckWritable(path string) error {
|
||||
f, err := os.CreateTemp(path, ".jukebox-writecheck-*")
|
||||
if err != nil {
|
||||
@@ -112,13 +87,3 @@ func InitDisk(mountPath string) (string, error) {
|
||||
func DBPath(mountPath string) string {
|
||||
return filepath.Join(mountPath, MarkerDir, "history.db")
|
||||
}
|
||||
|
||||
func DiskUsage(mountPath string) (total, free int64, err error) {
|
||||
var stat syscall.Statfs_t
|
||||
if err = syscall.Statfs(mountPath, &stat); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
total = int64(stat.Blocks) * int64(stat.Bsize)
|
||||
free = int64(stat.Bavail) * int64(stat.Bsize)
|
||||
return total, free, nil
|
||||
}
|
||||
|
||||
43
internal/disk/storage_unix.go
Normal file
43
internal/disk/storage_unix.go
Normal file
@@ -0,0 +1,43 @@
|
||||
//go:build !windows
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func IsMountPoint(path string) bool {
|
||||
pathInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
parent := filepath.Dir(filepath.Clean(path))
|
||||
parentInfo, err := os.Stat(parent)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
pathStat, ok := pathInfo.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
parentStat, ok := parentInfo.Sys().(*syscall.Stat_t)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return pathStat.Dev != parentStat.Dev
|
||||
}
|
||||
|
||||
func DiskUsage(mountPath string) (total, free int64, err error) {
|
||||
var stat syscall.Statfs_t
|
||||
if err = syscall.Statfs(mountPath, &stat); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
total = int64(stat.Blocks) * int64(stat.Bsize)
|
||||
free = int64(stat.Bavail) * int64(stat.Bsize)
|
||||
return total, free, nil
|
||||
}
|
||||
40
internal/disk/storage_windows.go
Normal file
40
internal/disk/storage_windows.go
Normal file
@@ -0,0 +1,40 @@
|
||||
//go:build windows
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func IsMountPoint(path string) bool {
|
||||
clean := filepath.Clean(path)
|
||||
volume := filepath.VolumeName(clean)
|
||||
if volume == "" {
|
||||
return false
|
||||
}
|
||||
root := volume + `\`
|
||||
return strings.EqualFold(clean, root)
|
||||
}
|
||||
|
||||
func DiskUsage(mountPath string) (total, free int64, err error) {
|
||||
root := filepath.Clean(mountPath)
|
||||
if volume := filepath.VolumeName(root); volume != "" {
|
||||
root = volume + `\`
|
||||
}
|
||||
|
||||
pathPtr, err := windows.UTF16PtrFromString(root)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
var freeBytesAvailable uint64
|
||||
var totalNumberOfBytes uint64
|
||||
var totalNumberOfFreeBytes uint64
|
||||
if err := windows.GetDiskFreeSpaceEx(pathPtr, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return int64(totalNumberOfBytes), int64(freeBytesAvailable), nil
|
||||
}
|
||||
Reference in New Issue
Block a user