use a new thread safe map

This commit is contained in:
Ben Sarmiento
2023-11-18 12:53:39 +01:00
parent b669f8d673
commit 0e9302f3b5
15 changed files with 577 additions and 535 deletions

View File

@@ -1,11 +1,13 @@
package zfs
import (
"fmt"
"strings"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/chunk"
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/winfsp/cgofuse/fuse"
"go.uber.org/zap"
)
@@ -98,6 +100,7 @@ func (fs *ZurgFS) Getattr(path string, stat *fuse.Stat_t, fh uint64) (errc int)
func (fs *ZurgFS) Read(path string, buff []byte, ofst int64, fh uint64) (n int) {
segments := splitIntoSegments(path)
fmt.Println("seg", segments)
if len(segments) != 3 {
return -fuse.ENOENT
} else if directory, dirFound := fs.TorrentManager.DirectoryMap.Get(segments[0]); !dirFound {
@@ -138,30 +141,30 @@ func (fs *ZurgFS) Readdir(path string,
case 0:
fill(".", nil, 0)
fill("..", nil, 0)
for el := fs.TorrentManager.DirectoryMap.Front(); el != nil; el = el.Next() {
fill(el.Key, nil, 0)
}
fs.TorrentManager.DirectoryMap.IterCb(func(directoryName string, _ cmap.ConcurrentMap[string, *torrent.Torrent]) {
fill(directoryName, nil, 0)
})
case 1:
fill(".", nil, 0)
fill("..", nil, 0)
if directory, dirFound := fs.TorrentManager.DirectoryMap.Get(segments[0]); !dirFound {
if torrents, dirFound := fs.TorrentManager.DirectoryMap.Get(segments[0]); !dirFound {
return -fuse.ENOENT
} else {
for el := directory.Front(); el != nil; el = el.Next() {
fill(el.Key, nil, 0)
}
torrents.IterCb(func(accessKey string, _ *torrent.Torrent) {
fill(accessKey, nil, 0)
})
}
case 2:
fill(".", nil, 0)
fill("..", nil, 0)
if directory, dirFound := fs.TorrentManager.DirectoryMap.Get(segments[0]); !dirFound {
if torrents, dirFound := fs.TorrentManager.DirectoryMap.Get(segments[0]); !dirFound {
return -fuse.ENOENT
} else if torrent, torFound := directory.Get(segments[1]); !torFound {
} else if tor, torFound := torrents.Get(segments[1]); !torFound {
return -fuse.ENOENT
} else {
for el := torrent.SelectedFiles.Front(); el != nil; el = el.Next() {
fill(el.Key, nil, 0)
}
tor.SelectedFiles.IterCb(func(filename string, _ *torrent.File) {
fill(filename, nil, 0)
})
}
default:
return -fuse.ENOENT