]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix build on Windows
authorMatt Joiner <anacrolix@gmail.com>
Fri, 8 Aug 2025 03:29:22 +0000 (13:29 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 8 Aug 2025 03:29:22 +0000 (13:29 +1000)
storage/file-piece.go
storage/seek-data_unix.go [new file with mode: 0644]
storage/seek-data_windows.go [new file with mode: 0644]

index d50c509a338772a70cef7dea5e4c3b5c2823e997..54f1556b02d8792ea7b8021dafcb19baa058dee7 100644 (file)
@@ -12,8 +12,6 @@ import (
 
        g "github.com/anacrolix/generics"
        "github.com/anacrolix/missinggo/v2/panicif"
-       "golang.org/x/sys/unix"
-
        "github.com/anacrolix/torrent/metainfo"
        "github.com/anacrolix/torrent/segments"
 )
@@ -318,10 +316,8 @@ func (me *filePieceImpl) writeFileTo(w io.Writer, fileIndex int, extent segments
        panicif.GreaterThan(extent.End(), file.FileInfo.Length)
        extentRemaining := extent.Length
        var dataOffset int64
-       dataOffset, err = unix.Seek(int(f.Fd()), extent.Start, unix.SEEK_DATA)
-       if err == unix.ENXIO {
-               // File has no more data. Treat as short write like io.CopyN.
-               err = io.EOF
+       dataOffset, err = seekData(f, extent.Start)
+       if err == io.EOF {
                return
        }
        panicif.Err(err)
diff --git a/storage/seek-data_unix.go b/storage/seek-data_unix.go
new file mode 100644 (file)
index 0000000..35e0dee
--- /dev/null
@@ -0,0 +1,19 @@
+//go:build unix
+
+package storage
+
+import (
+       "io"
+       "os"
+
+       "golang.org/x/sys/unix"
+)
+
+func seekData(f *os.File, offset int64) (ret int64, err error) {
+       ret, err = unix.Seek(int(f.Fd()), offset, unix.SEEK_DATA)
+       if err == unix.ENXIO {
+               // File has no more data. Treat as short write like io.CopyN.
+               err = io.EOF
+       }
+       return
+}
diff --git a/storage/seek-data_windows.go b/storage/seek-data_windows.go
new file mode 100644 (file)
index 0000000..ccfe202
--- /dev/null
@@ -0,0 +1,10 @@
+package storage
+
+import (
+       "io"
+       "os"
+)
+
+func seekData(f *os.File, offset int64) (ret int64, err error) {
+       return f.Seek(offset, io.SeekStart)
+}