From 988889e8bde878757ee01d2e88f5f0f3302951a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E7=AB=9E=E5=AE=81?= Date: Fri, 7 Oct 2022 12:24:39 +0800 Subject: [PATCH] fix: fs syscall --- autofill.go | 18 +++++++----------- fs.go | 16 ++++++++-------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/autofill.go b/autofill.go index abba816..33a6827 100644 --- a/autofill.go +++ b/autofill.go @@ -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 } diff --git a/fs.go b/fs.go index 1aeda4e..edfcf15 100644 --- a/fs.go +++ b/fs.go @@ -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