|
|
|
|
@@ -193,9 +193,9 @@ func (q *QBit) ProcessSymlink(torrent *Torrent) (string, error) {
|
|
|
|
|
}
|
|
|
|
|
pending[file.Path] = file
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ticker := time.NewTicker(200 * time.Millisecond)
|
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
|
|
|
|
|
timeout := time.After(30 * time.Minute)
|
|
|
|
|
filePaths := make([]string, 0, len(pending))
|
|
|
|
|
|
|
|
|
|
@@ -300,70 +300,6 @@ func (q *QBit) createSymlinksWebdav(debridTorrent *debridTypes.Torrent, rclonePa
|
|
|
|
|
return symlinkPath, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *QBit) createSymlinks(debridTorrent *debridTypes.Torrent, rclonePath, torrentFolder string) (string, error) {
|
|
|
|
|
files := debridTorrent.Files
|
|
|
|
|
symlinkPath := filepath.Join(q.DownloadFolder, debridTorrent.Arr.Name, torrentFolder) // /mnt/symlinks/{category}/MyTVShow/
|
|
|
|
|
err := os.MkdirAll(symlinkPath, os.ModePerm)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", fmt.Errorf("failed to create directory: %s: %v", symlinkPath, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remainingFiles := make(map[string]debridTypes.File)
|
|
|
|
|
for _, file := range files {
|
|
|
|
|
remainingFiles[file.Path] = file
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ticker := time.NewTicker(100 * time.Millisecond)
|
|
|
|
|
defer ticker.Stop()
|
|
|
|
|
timeout := time.After(30 * time.Minute)
|
|
|
|
|
filePaths := make([]string, 0, len(files))
|
|
|
|
|
|
|
|
|
|
for len(remainingFiles) > 0 {
|
|
|
|
|
select {
|
|
|
|
|
case <-ticker.C:
|
|
|
|
|
entries, err := os.ReadDir(rclonePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check which files exist in this batch
|
|
|
|
|
for _, entry := range entries {
|
|
|
|
|
filename := entry.Name()
|
|
|
|
|
if file, exists := remainingFiles[filename]; exists {
|
|
|
|
|
fullFilePath := filepath.Join(rclonePath, filename)
|
|
|
|
|
fileSymlinkPath := filepath.Join(symlinkPath, file.Name)
|
|
|
|
|
|
|
|
|
|
if err := os.Symlink(fullFilePath, fileSymlinkPath); err != nil && !os.IsExist(err) {
|
|
|
|
|
q.logger.Debug().Msgf("Failed to create symlink: %s: %v", fileSymlinkPath, err)
|
|
|
|
|
} else {
|
|
|
|
|
filePaths = append(filePaths, fileSymlinkPath)
|
|
|
|
|
delete(remainingFiles, filename)
|
|
|
|
|
q.logger.Info().Msgf("File is ready: %s", file.Name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case <-timeout:
|
|
|
|
|
q.logger.Warn().Msgf("Timeout waiting for files, %d files still pending", len(remainingFiles))
|
|
|
|
|
return symlinkPath, fmt.Errorf("timeout waiting for files")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if q.SkipPreCache {
|
|
|
|
|
return symlinkPath, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
|
|
if err := q.preCacheFile(debridTorrent.Name, filePaths); err != nil {
|
|
|
|
|
q.logger.Error().Msgf("Failed to pre-cache file: %s", err)
|
|
|
|
|
} else {
|
|
|
|
|
q.logger.Trace().Msgf("Pre-cached %d files", len(filePaths))
|
|
|
|
|
}
|
|
|
|
|
}() // Pre-cache the files in the background
|
|
|
|
|
return symlinkPath, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (q *QBit) getTorrentPath(rclonePath string, debridTorrent *debridTypes.Torrent) (string, error) {
|
|
|
|
|
for {
|
|
|
|
|
torrentPath, err := debridTorrent.GetMountFolder(rclonePath)
|
|
|
|
|
|