diff --git a/src/sources/torrent/storage_dedupe.go b/src/sources/torrent/storage_dedupe.go index 4b9a8ca..04b086d 100644 --- a/src/sources/torrent/storage_dedupe.go +++ b/src/sources/torrent/storage_dedupe.go @@ -118,12 +118,12 @@ func (s *fileStorage) dedupeFiles(ctx context.Context, paths []string) (deduped srcF, err := os.Open(paths[0]) if err != nil { - return deduped, err + return deduped, fmt.Errorf("error opening file %s: %w", paths[0], err) } defer srcF.Close() srcStat, err := srcF.Stat() if err != nil { - return deduped, err + return deduped, fmt.Errorf("error stat file %s: %w", paths[0], err) } srcFd := int(srcF.Fd()) @@ -133,12 +133,12 @@ func (s *fileStorage) dedupeFiles(ctx context.Context, paths []string) (deduped err = unix.Fstatfs(srcFd, &fsStat) if err != nil { span.RecordError(err) - return deduped, err + return deduped, fmt.Errorf("error statfs file %s: %w", paths[0], err) } srcHash, err := filehash(srcF) if err != nil { - return deduped, err + return deduped, fmt.Errorf("error hashing file %s: %w", paths[0], err) } if int64(fsStat.Bsize) > srcSize { // for btrfs it means file in residing in not deduplicatable metadata @@ -162,13 +162,13 @@ func (s *fileStorage) dedupeFiles(ctx context.Context, paths []string) (deduped destF, err := os.OpenFile(dst, os.O_RDWR, os.ModePerm) if err != nil { - return deduped, err + return deduped, fmt.Errorf("error opening file %s: %w", dst, err) } defer destF.Close() dstHash, err := filehash(destF) if err != nil { - return deduped, err + return deduped, fmt.Errorf("error hashing file %s: %w", dst, err) } if srcHash != dstHash { @@ -199,7 +199,7 @@ func (s *fileStorage) dedupeFiles(ctx context.Context, paths []string) (deduped err = unix.IoctlFileDedupeRange(srcFd, &rng) if err != nil { - return deduped, err + return deduped, fmt.Errorf("error calling FIDEDUPERANGE: %w", err) } for i := range rng.Info { @@ -223,7 +223,3 @@ func filehash(r io.Reader) ([20]byte, error) { return sha1.Sum(buf), nil } - -func ptr[D any](v D) *D { - return &v -}