fix: fs syscall

This commit is contained in:
崔竞宁
2022-10-07 12:24:39 +08:00
parent b76cde8fa4
commit 988889e8bd
2 changed files with 15 additions and 19 deletions

View File

@@ -19,8 +19,8 @@ func (c *Copyer) applyAutoFillLimit() error {
return fmt.Errorf("get file system fail, %s, %w", d, err)
}
infos[fsInfo.MountPoint] = fsInfo
counts[fsInfo.MountPoint] = counts[fsInfo.MountPoint] + 1
infos[d] = fsInfo
counts[d] = counts[d] + 1
}
min := int64(math.MaxInt64)
@@ -46,19 +46,15 @@ func (c *Copyer) applyAutoFillLimit() error {
c.jobs = c.jobs[:idx]
last := ""
for _, job := range cutoff {
job.parent.done(job)
if job.parent != nil {
job.parent.done(job)
}
if strings.HasPrefix(job.source.relativePath, last) {
if len(job.source.relativePath) == len(last) {
continue
}
if job.source.relativePath[len(last)] == '/' {
continue
}
continue
}
c.noSpaceSource = append(c.noSpaceSource, job.source)
last = job.source.relativePath
last = job.source.relativePath + "/"
}
return nil
}

16
fs.go
View File

@@ -2,26 +2,26 @@ package acp
import (
"fmt"
"syscall"
"golang.org/x/sys/unix"
)
type fileSystem struct {
TypeName string
MountPoint string
// TypeName string
// MountPoint string
TotalSize int64
AvailableSize int64
}
func getFileSystem(path string) (*fileSystem, error) {
stat := new(syscall.Statfs_t)
if err := syscall.Statfs(path, stat); err != nil {
stat := new(unix.Statfs_t)
if err := unix.Statfs(path, stat); err != nil {
return nil, fmt.Errorf("read statfs fail, err= %w", err)
}
return &fileSystem{
TypeName: unpaddingInt8s(stat.Fstypename[:]),
MountPoint: unpaddingInt8s(stat.Mntonname[:]),
// TypeName: unpaddingInt8s(stat.Fstypename[:]),
// MountPoint: unpaddingInt8s(stat.Mntonname[:]),
TotalSize: int64(stat.Blocks) * int64(stat.Bsize),
AvailableSize: int64(stat.Bavail) * int64(stat.Bsize),
}, nil