storj/storage/filestore/dir_unix.go
Egon Elbre 080ba47a06 all: fix dots
Change-Id: I6a419c62700c568254ff67ae5b73efed2fc98aa2
2020-07-16 14:58:28 +00:00

44 lines
1015 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// +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
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)
}