2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-09-28 07:59:27 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package filestore
|
|
|
|
|
|
|
|
import (
|
2020-07-14 14:04:38 +01:00
|
|
|
"errors"
|
2018-09-28 07:59:27 +01:00
|
|
|
"fmt"
|
2019-03-11 08:06:56 +00:00
|
|
|
"os"
|
2018-09-28 07:59:27 +01:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func isBusy(err error) bool {
|
|
|
|
err = underlyingError(err)
|
2020-07-14 14:04:38 +01:00
|
|
|
return errors.Is(err, unix.EBUSY)
|
2018-09-28 07:59:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
filesystemID := fmt.Sprintf("%08x%08x", stat.Fsid.Val[0], stat.Fsid.Val[1])
|
|
|
|
|
|
|
|
return DiskInfo{filesystemID, availableSpace}, nil
|
|
|
|
}
|
2019-03-11 08:06:56 +00:00
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// rename renames oldpath to newpath.
|
2019-03-11 08:06:56 +00:00
|
|
|
func rename(oldpath, newpath string) error {
|
|
|
|
return os.Rename(oldpath, newpath)
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// openFileReadOnly opens the file with read only.
|
2019-03-11 08:06:56 +00:00
|
|
|
func openFileReadOnly(path string, perm os.FileMode) (*os.File, error) {
|
|
|
|
return os.OpenFile(path, os.O_RDONLY, perm)
|
|
|
|
}
|