Skip to content
Merged

. #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions config/altmount.log

This file was deleted.

16 changes: 16 additions & 0 deletions internal/importer/filesystem/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ func CalculateVirtualDirectory(nzbPath, relativePath string) string {
return "/"
}

// Ignore .nzbs folder if present (persistent storage)
if strings.Contains(relDir, ".nzbs") {
parts := strings.Split(relDir, string(filepath.Separator))
filtered := make([]string, 0, len(parts))
for _, p := range parts {
if p != ".nzbs" {
filtered = append(filtered, p)
}
}
relDir = filepath.Join(filtered...)
}

if relDir == "." || relDir == "" {
return "/"
}

virtualPath := "/" + strings.ReplaceAll(relDir, string(filepath.Separator), "/")
return filepath.Clean(virtualPath)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/importer/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ func TestCalculateVirtualDirectory(t *testing.T) {
relativePath: "/downloads/sonarr",
expected: "/",
},
{
name: "file in persistent .nzbs directory",
nzbPath: "/config/.nzbs/MovieFolder/Movie.nzb",
relativePath: "/config",
expected: "/MovieFolder",
},
}

for _, tt := range tests {
Expand Down
15 changes: 14 additions & 1 deletion internal/importer/scanner/nzbdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (n *NzbDavImporter) performImport(ctx context.Context, dbPath string, rootF
}

// Create workers
numWorkers := 20 // 20 parallel workers for file creation
numWorkers := 4 // Use fewer parallel workers for file creation
var workerWg sync.WaitGroup
batchChan := make(chan *database.ImportQueueItem, 100)

Expand All @@ -145,6 +145,19 @@ func (n *NzbDavImporter) performImport(ctx context.Context, dbPath string, rootF
n.processBatch(ctx, batchChan)
}()

// Monitor error channel in background to catch query/DB failures early
go func() {
for err := range errChan {
if err != nil {
n.log.ErrorContext(ctx, "Error during NZBDav parsing", "error", err)
n.mu.Lock()
msg := err.Error()
n.info.LastError = &msg
n.mu.Unlock()
}
}
}()

// Start workers
for i := 0; i < numWorkers; i++ {
workerWg.Add(1)
Expand Down
21 changes: 0 additions & 21 deletions internal/importer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,27 +558,6 @@ func (s *Service) calculateProcessVirtualDir(item *database.ImportQueueItem, bas
// Calculate initial virtual directory from physical/relative path
virtualDir := filesystem.CalculateVirtualDirectory(item.NzbPath, *basePath)

// Fix for issue where files moved to persistent .nzbs directory end up with exposed .nzbs path in virtual directory
// This happens when RelativePath is "/" (e.g. from NZBDav or root watch) and NzbPath is inside .nzbs
nzbFolder := s.GetNzbFolder()
// Check if NzbPath is inside the persistent NZB folder
if strings.HasPrefix(item.NzbPath, nzbFolder) {
// If virtualDir contains the .nzbs folder name, it means CalculateVirtualDirectory
// included it because the file is physically there.
// We want to hide this implementation detail.
if strings.Contains(virtualDir, filepath.Base(nzbFolder)) {
if *basePath == "" {
virtualDir = "/"
} else {
virtualDir = *basePath
if !strings.HasPrefix(virtualDir, "/") {
virtualDir = "/" + virtualDir
}
virtualDir = filepath.ToSlash(virtualDir)
}
}
}

// If category is specified, resolve to configured directory path
if item.Category != nil && *item.Category != "" {
categoryPath := s.buildCategoryPath(*item.Category)
Expand Down
Loading
Loading