storj/storagenode/blobstore/filestore/dir_unix.go
Egon Elbre f5020de57c storagenode/blobstore: move blob store logic
The blobstore implementation is entirely related to storagenode, so the
rightful place is together with the storagenode implementation.

Fixes https://github.com/storj/storj/issues/5754

Change-Id: Ie6637b0262cf37af6c3e558556c7604d9dc3613d
2023-04-05 18:06:20 +00:00

45 lines
1.0 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
//go:build !windows
// +build !windows
package filestore
import (
"errors"
"fmt"
"os"
"golang.org/x/sys/unix"
)
func isBusy(err error) bool {
err = underlyingError(err)
return errors.Is(err, unix.EBUSY)
}
func diskInfoFromPath(path string) (info DiskInfo, err error) {
var stat unix.Statfs_t
err = unix.Statfs(path, &stat)
if err != nil {
return DiskInfo{"", -1}, err
}
// the Bsize size depends on the OS and unconvert gives a false-positive
availableSpace := int64(stat.Bavail) * int64(stat.Bsize) //nolint: unconvert
filesystemID := fmt.Sprintf("%08x%08x", stat.Fsid.Val[0], stat.Fsid.Val[1])
return DiskInfo{filesystemID, availableSpace}, nil
}
// rename renames oldpath to newpath.
func rename(oldpath, newpath string) error {
return os.Rename(oldpath, newpath)
}
// openFileReadOnly opens the file with read only.
func openFileReadOnly(path string, perm os.FileMode) (*os.File, error) {
return os.OpenFile(path, os.O_RDONLY, perm)
}