]> Sergey Matveev's repositories - btrtrc.git/blobdiff - storage/file.go
Shortened long filenames
[btrtrc.git] / storage / file.go
index aa67df15f486f463fd3a47554ecc83d0691009dc..6871cad31a06cbe84754dc78a848379daa3e7024 100644 (file)
@@ -115,7 +115,7 @@ func (fs fileClientImpl) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash
                        length: fileInfo.Length,
                }
                if f.length == 0 {
-                       err = CreateNativeZeroLengthFile(f.path)
+                       err = CreateNativeZeroLengthFile(PathShortener(f.path))
                        if err != nil {
                                err = fmt.Errorf("creating zero length file: %w", err)
                                return
@@ -185,10 +185,11 @@ type fileTorrentImplIO struct {
 // Returns EOF on short or missing file.
 func (fst *fileTorrentImplIO) readFileAt(file file, b []byte, off int64) (n int, err error) {
        fdRCacheM.Lock()
-       centry := fdRCache[file.path]
+       pth := PathShortener(file.path)
+       centry := fdRCache[pth]
        if centry == nil {
                var fd *os.File
-               fd, err = os.Open(file.path)
+               fd, err = os.Open(pth)
                if os.IsNotExist(err) {
                        // File missing is treated the same as a short file.
                        err = io.EOF
@@ -198,7 +199,7 @@ func (fst *fileTorrentImplIO) readFileAt(file file, b []byte, off int64) (n int,
                        return
                }
                centry = &fdCacheEntry{fd: fd}
-               fdRCache[file.path] = centry
+               fdRCache[pth] = centry
        }
        fdRCacheM.Unlock()
        // Limit the read to within the expected bounds of this file.
@@ -229,7 +230,7 @@ func (fst fileTorrentImplIO) ReadAt(b []byte, off int64) (n int, err error) {
 
 func (fst fileTorrentImplIO) WriteAt(p []byte, off int64) (n int, err error) {
        fst.fts.segmentLocater.Locate(segments.Extent{off, int64(len(p))}, func(i int, e segments.Extent) bool {
-               name := fst.fts.files[i].path
+               name := PathShortener(fst.fts.files[i].path)
                _, ok := fdMkdirAllCache[filepath.Dir(name)]
                if !ok {
                        os.MkdirAll(filepath.Dir(name), 0o777)