Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
88dbc88
fix(scanner): skip hidden files and __MACOSX folders in every library
Rhainland Dec 6, 2026
49a7bf0
fix(themesongs): never treat a hidden file as a theme song
Rhainland Dec 6, 2026
39695bd
test(scanner): keep only hidden-file cases that fail without the fix
Rhainland Dec 6, 2026
4004d39
docs(scanner): list every place the hidden-file rule applies
Rhainland Dec 6, 2026
a93557e
test(scanner): cover hidden audio files in the audiobook scan
Rhainland Dec 6, 2026
a686a95
docs(scanner): keep ignore files out of the hidden-file rule's wording
Rhainland Dec 6, 2026
b2691b6
fix(scanner): never treat a hidden file as a local metadata or subtit…
Rhainland Dec 6, 2026
fe37fdf
fix(scantrigger): reject a hidden file as ignored, not as an unsuppor…
Rhainland Dec 6, 2026
0e7d1e3
chore(i18n): sync the autoscan path_ignored reason from the catalog
Rhainland Dec 6, 2026
cdba182
fix(scantrigger): keep treating ignore-file changes as scannable fold…
Rhainland Dec 6, 2026
60bb029
fix(autoscan): record a deleted hidden file as ignored, not unresolved
Rhainland Dec 6, 2026
1b093c4
docs(scanner): describe ignore files as the hidden-file exception
Rhainland Dec 6, 2026
ce46fe6
fix(abs): acknowledge watcher updates for hidden files without scanning
Rhainland Dec 6, 2026
21f40ad
docs(scanner): name the entry points that skip hidden-file changes
Rhainland Dec 6, 2026
bc306b3
fix(abs): keep scanning watcher updates for dot-named directories
Rhainland Dec 6, 2026
fe125d9
fix(abs): acknowledge watcher updates that scans skip, as the resolve…
Rhainland Dec 6, 2026
cb478ed
fix(autoscan): record a legacy change in a deleted hidden folder as i…
Rhainland Dec 6, 2026
46d1a5b
docs(scanner): note vanished hidden folders and the watcher's ignored…
Rhainland Dec 6, 2026
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
4 changes: 2 additions & 2 deletions .silo-translations
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
platform=web
version=2026.12.05-95a7440
sha256=23d4c6836d55d337939d391d9e07fd667e7a7294117f95d2cfd7fce2df11ad9d
version=local-94d58a430627

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Pin the published catalog release before merging.

A bare scripts/sync-translations now rejects this local pin. Merge the catalog change, then sync its published release.

As per coding guidelines, “Before the client pull request merges, re-sync with --version <release>” so the pin names a published release.

Source: Coding guidelines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Planned: this branch re-syncs with --version <release> once Silo-Server/silo-translations#234 is released, before merge. See Risks in the PR body.

sha256=-
Comment on lines +2 to +3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

Local translation pin prevents reinstalling the pinned catalog

A fresh checkout cannot reinstall the pinned translations because scripts/sync-translations rejects local-* versions. Pin the published release and its checksum when the catalog change is released.

Prompt for LLM
File .silo-translations, lines 2-3:

Local translation pin prevents reinstalling the pinned catalog

The local-build pin makes `scripts/sync-translations` without arguments fail because the script explicitly rejects `local-*` versions, so a fresh checkout cannot reinstall the pinned translations without a separate catalog checkout. Pin the published translation release and its checksum when the catalog change is released.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known and listed under Risks: the pin points at a local build of Silo-Server/silo-translations#234 while that PR is open. Once its release is published, this branch re-syncs with --version <release> before merge, which replaces the pin and checksum.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. The local pin is a known temporary state, and the PR already documents the plan to replace it with the published release and checksum before merge. This is a pre-merge follow-up, not an additional finding.

8 changes: 6 additions & 2 deletions cmd/silo/abs_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/Silo-Server/silo-server/internal/catalog"
"github.com/Silo-Server/silo-server/internal/models"
"github.com/Silo-Server/silo-server/internal/opslog"
"github.com/Silo-Server/silo-server/internal/scantrigger"
"github.com/Silo-Server/silo-server/internal/serversettings"
)

Expand Down Expand Up @@ -68,11 +69,14 @@ func absAdminServices(services abs.AdminServices, router api.AdminHandlers, sett
return services
}

// absAdminError carries a handler refusal's status and message.
// absAdminError carries a handler refusal's status and message, and marks a
// scan refused for a path that scans skip.
func absAdminError(err error) error {
var apiErr *handlers.APIError
if errors.As(err, &apiErr) {
return &abs.AdminError{Status: apiErr.Status, Message: apiErr.Message}
reqErr, ok := errors.AsType[*scantrigger.RequestError](err)
ignored := ok && reqErr.Reason == scantrigger.ReasonPathIgnored
return &abs.AdminError{Status: apiErr.Status, Message: apiErr.Message, Ignored: ignored}
}
return err
}
Expand Down
25 changes: 25 additions & 0 deletions cmd/silo/abs_admin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"errors"
"net/http"
"testing"

"github.com/Silo-Server/silo-server/internal/api/handlers"
"github.com/Silo-Server/silo-server/internal/audiobooks/abs"
"github.com/Silo-Server/silo-server/internal/scantrigger"
)

func TestABSAdminErrorMarksIgnoredScanPaths(t *testing.T) {
refusal := func(reason scantrigger.Reason) error {
return (&handlers.APIError{Status: http.StatusBadRequest, Code: "bad_request", Message: "refused"}).
WithCause(&scantrigger.RequestError{Status: http.StatusBadRequest, Reason: reason})
}
var ae *abs.AdminError
if !errors.As(absAdminError(refusal(scantrigger.ReasonPathIgnored)), &ae) || !ae.Ignored || ae.Status != http.StatusBadRequest {
t.Fatalf("path_ignored: got %+v, want an ignored 400", ae)
}
if !errors.As(absAdminError(refusal(scantrigger.ReasonUnsupportedExtension)), &ae) || ae.Ignored {
t.Fatalf("unsupported_extension: got %+v, want a refusal that is not ignored", ae)
}
}
2 changes: 1 addition & 1 deletion docs/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3655,7 +3655,7 @@ change logging have an empty list. Each change has `source_path` (as reported),
same scope that was already queued or running), `suppressed` (debounced),
`unresolved` (did not map to a scannable library location), `ignored` (empty path,
a file change that resolved to a whole library, or a file the library's ignore files
exclude) or `error` (resolve or enqueue failure). `reason` is a machine code for
exclude or that is hidden) or `error` (resolve or enqueue failure). `reason` is a machine code for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

Qualify the hidden-file outcome.

A legacy auto change for Movie/._Movie.mkv resolves its parent and can be queued. A structured change for .nomedia is exempt from the hidden-file check and can be unresolved. Limit this description to the hidden-file changes that the resolver rejects with path_ignored.


Minor · Data Integrity & Integration · Quick win

Qualify the ignore-file outcome.

A movie file below the library root can match .siloignore and still produce a queued outcome. The resolver widens it to a subtree scan before it checks file-level ignore rules. Describe ignored as the outcome when the resolver rejects the path, rather than for every excluded file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that the sentence overreaches: legacy auto changes are grouped by parent folder, so a hidden file reported that way can still queue its folder. I'll narrow it to structured file changes for hidden files in the push that re-syncs the translations release, so the branch moves once.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rhainland Thanks. I’m not marking the finding as addressed while the change is pending.


Learnings added

Learnt from: Rhainland
Repo: Silo-Server/silo-server PR: 5931
File: docs/admin-api.md:3658-3658
Timestamp: 2026-12-06T16:05:45.559Z
Learning: Within repository "Silo-Server/silo-server", only for files matching one of ["docs/admin-api.md"]: When reviewing Autoscan poll-event outcome documentation in docs/admin-api.md, do not assume every hidden-file report has an ignored outcome. Legacy `auto` changes are grouped by parent folder, so a hidden-file report can queue its folder.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

unresolved, ignored and error outcomes: resolver reasons such as `no_library_match`,
`library_root_offline`, `unsupported_extension` or `path_ignored`, plus
`resolves_to_library`, `resolve_failed` and `enqueue_failed`; clients treat unknown codes and unknown outcomes as opaque and
Expand Down
10 changes: 7 additions & 3 deletions docs/architecture/realtime-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,13 @@ directories the scanner would enter (`walkTree`). They skip:
dropped from events before tracking, and a rename from an ignored name
(`movie.mkv.part` to `movie.mkv`) counts as a move in.
- Every directory the scanner skips by name (`scanner.SkippedDirName`): any
hidden (dot-prefixed) directory, and `@Recycle` and `$RECYCLE.BIN`
(case-insensitive). See
[scanner ignore files](scanner-ignore-files.md#hidden-and-housekeeping-directories).
hidden (dot-prefixed) directory, and `@Recycle`, `$RECYCLE.BIN`, and
`__MACOSX` (case-insensitive). See
[scanner ignore files](scanner-ignore-files.md#hidden-files-and-housekeeping-directories).
Events for other hidden files are not dropped here: a hidden media,
sidecar, or theme file never resolves to a scan target
(`scanner.SkippedFileName`). The ignore files `.nomedia`, `.ignore`, and
`.siloignore` are hidden too and keep the handling described below.
- A directory holding a regular `.nomedia` file, or a regular `.ignore` file
without a valid pattern, is skipped with everything below it. The decision
is the scanner's own (`scanner.DirSkipped`, see
Expand Down
29 changes: 24 additions & 5 deletions docs/architecture/scanner-ignore-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,33 @@ principles as Plex's `.plexignore`:
does not cross `/`. A pattern therefore only matches files directly inside
the directory unless it contains an explicit `/` path, e.g. `Season 2/*.mkv`.

## Hidden and housekeeping directories
## Hidden files and housekeeping directories

Without any ignore file, every walker skips a directory below a configured
library root whose name starts with `.`, as Jellyfin does, and the NAS and OS
housekeeping folders `@eaDir`, `@Recycle`, `#recycle`, and `$RECYCLE.BIN`
(case-insensitive). The rule is `scanner.SkippedDirName`, which the real-time
monitor shares. A skipped directory is never read, so one the scan cannot open
is not a walk failure. Hidden files are not skipped by this rule.
housekeeping folders `@eaDir`, `@Recycle`, `#recycle`, `$RECYCLE.BIN`, and
`__MACOSX` (case-insensitive). The rule is `scanner.SkippedDirName`, which the
real-time monitor shares. A skipped directory is never read, so one the scan
cannot open is not a walk failure.

Hidden (dot-prefixed) files are skipped too (`scanner.SkippedFileName`): they
are never media, subtitle sidecars, or theme songs. This covers the AppleDouble
`._` file macOS writes beside every file it copies to a network share, which
keeps the original's extension. The check lives in `SupportsVideoFile`,
`SupportsAudioFile`, `SupportsEbookFile`, the sidecar checks
(`IsLocalMetadataSidecar`, `IsSubtitleSidecar`, and the subtitle listing), and
`themesongs.OwnerDirectory`, so every walker, single-file scan, and monitor
event applies it. The scan resolver rejects a hidden file, and a vanished
hidden file or folder, with `path_ignored`, the reason it gives a path the
library's ignore files exclude (`scanner.HiddenFile`), so a monitor file
event, a structured autoscan file change, or an Audiobookshelf watcher update
for one queues no scan. The Audiobookshelf watcher answers any `path_ignored`
refusal with 200 OK.

The ignore files `.ignore`, `.siloignore`, and `.nomedia` are hidden too but
are read as described above, not skipped (`scanner.IsIgnoreFile`): the
resolver does not reject a change to one as hidden, and the real-time monitor
still rescans its directory.

A configured library root is walked whatever its name, unless it lies inside
another configured root of the same library (see Scan behavior). A subtree scan whose
Expand Down
2 changes: 1 addition & 1 deletion docs/scan-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Errors are RFC 9457 problem documents. The trailing segment of `type` is the sta

| Status | Problem code | Cause |
| ------ | ------------------------ | ----- |
| 400 | `malformed_request` | Malformed JSON body, or a target the resolver rejects: neither `library_id` nor `path` supplied, a path outside the library's roots, a missing or uninspectable path, a path that is neither file nor directory, a permission-denied path, an ambiguous path matching several libraries, or an unsupported media extension. |
| 400 | `malformed_request` | Malformed JSON body, or a target the resolver rejects: neither `library_id` nor `path` supplied, a path outside the library's roots, a missing or uninspectable path, a path that is neither file nor directory, a permission-denied path, an ambiguous path matching several libraries, an unsupported media extension, or a hidden (dot-prefixed) file. |
| 401 | `authentication_required` / `invalid_token` / `session_expired` / `token_refresh_required` | Missing, unreadable, or expired credential, or an access token to refresh after a role change. |
| 403 | `permission_denied` | The caller is not an acting administrator. The demo-mode guard also answers here; it exempts acting administrators. |
| 403 | `profile_verification_required` | A PIN-protected profile without `X-Profile-Token`. |
Expand Down
4 changes: 2 additions & 2 deletions internal/api/handlers/libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (h *LibraryHandler) StartLibraryScan(ctx context.Context, libraryID *int, p
})
if err != nil {
if reqErr, ok := errors.AsType[*scantrigger.RequestError](err); ok {
return ScanAdmission{}, &APIError{Status: reqErr.Status, Code: reqErr.Code, Message: reqErr.Message}
return ScanAdmission{}, (&APIError{Status: reqErr.Status, Code: reqErr.Code, Message: reqErr.Message}).WithCause(reqErr)
}
slog.ErrorContext(ctx, "resolving scan target", "component", "api", "error", err)
return ScanAdmission{}, &APIError{Status: http.StatusInternalServerError, Code: scanControlInternalCode, Message: "Failed to resolve scan target"}
Expand All @@ -508,7 +508,7 @@ func (h *LibraryHandler) StartVanishedLibraryScan(ctx context.Context, libraryID
if reqErr.Reason == scantrigger.ReasonPathStillExists {
return h.StartLibraryScan(ctx, &libraryID, path)
}
return ScanAdmission{}, &APIError{Status: reqErr.Status, Code: reqErr.Code, Message: reqErr.Message}
return ScanAdmission{}, (&APIError{Status: reqErr.Status, Code: reqErr.Code, Message: reqErr.Message}).WithCause(reqErr)
}
slog.ErrorContext(ctx, "resolving vanished scan target", "component", "api", "error", err)
return ScanAdmission{}, &APIError{Status: http.StatusInternalServerError, Code: scanControlInternalCode, Message: "Failed to resolve scan target"}
Expand Down
3 changes: 3 additions & 0 deletions internal/audiobooks/abs/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func (h *Handler) SetAdmin(s AdminServices) {
type AdminError struct {
Status int
Message string
// Ignored marks a scan refused because scans skip the path, such as a
// hidden file.
Ignored bool
}

func (e *AdminError) Error() string { return e.Message }
Expand Down
5 changes: 5 additions & 0 deletions internal/audiobooks/abs/admin_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ func (h *Handler) handleWatcherUpdate(w http.ResponseWriter, r *http.Request) {
} else {
err = h.admin.Libraries.ScanLibrary(r.Context(), libs[i].ID, s.path)
}
if ae, ok := errors.AsType[*AdminError](err); ok && ae.Ignored {
// Scans skip this path, such as the "._" file macOS writes
// beside each copy, so its change needs no scan.
continue
}
if !alreadyRunning(err) && firstErr == nil {
firstErr = err
}
Expand Down
22 changes: 22 additions & 0 deletions internal/audiobooks/abs/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,25 @@ func TestValidABSCron(t *testing.T) {
}
}
}

// A watcher reports the "._" file macOS writes beside each copy like any
// other; scans skip hidden files, so it is acknowledged without a scan.
func TestWatcherUpdateAcknowledgesIgnoredPaths(t *testing.T) {
hb := newAdminHarness(t)
// Scans skip hidden files, such as the "._" file macOS writes beside
// each copy, and Silo refuses to scan one as ignored: the watcher
// acknowledges the change instead of failing it.
hb.world.runErr = &AdminError{Status: http.StatusBadRequest, Message: "Hidden files are not scanned", Ignored: true}
for _, kind := range []string{"add", "unlink"} {
body := `{"libraryId":"1","path":"/books/Author/Book/._Book.m4b","type":"` + kind + `"}`
if code, got := hb.do("1", http.MethodPost, "/api/watcher/update", body); code != http.StatusOK || got != "OK" {
t.Fatalf("%s = %d %q, want 200 OK", body, code, got)
}
}
// Any other refusal still reaches the watcher.
hb.world.runErr = &AdminError{Status: http.StatusBadRequest, Message: "Path is not within the requested library"}
body := `{"libraryId":"1","path":"/elsewhere/._Book.m4b","type":"unlink"}`
if code, _ := hb.do("1", http.MethodPost, "/api/watcher/update", body); code != http.StatusBadRequest {
t.Fatalf("%s = %d, want 400", body, code)
}
}
11 changes: 11 additions & 0 deletions internal/autoscan/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,12 @@ func (s *Service) resolveAndClaim(ctx context.Context, changes []Change, records
target, rerr = s.resolver.ResolveVanishedPath(ctx, dir, scanTrigger)
fallbackErr = rerr
}
if reqErr, ok := errors.AsType[*scantrigger.RequestError](rerr); ok && reqErr.Reason == scantrigger.ReasonPathIgnored {
// A deleted hidden folder: scans skip it, so it needs none.
resolvedAny = true
apply(func(rec *ChangeRecord) { rec.setOutcome(ChangeOutcomeIgnored, string(reqErr.Reason), reqErr.Message) })
continue
}
if rerr != nil {
var reqErr *scantrigger.RequestError
if errors.As(rerr, &reqErr) {
Expand Down Expand Up @@ -1135,6 +1141,11 @@ func (s *Service) resolveChange(ctx context.Context, change Change, stats *resol
primaryErr = err
target, err = s.resolver.ResolveVanishedFile(ctx, change.SourcePath, scanTrigger)
fallbackErr = err
if reqErr, ok := errors.AsType[*scantrigger.RequestError](err); ok && reqErr.Reason == scantrigger.ReasonPathIgnored {
// A deleted hidden file, ignored as it was while it existed.
rec.setOutcome(ChangeOutcomeIgnored, string(reqErr.Reason), reqErr.Message)
return nil, false
}
}
default:
target, err = s.resolver.Resolve(ctx, scantrigger.Request{Path: change.SourcePath, Trigger: scanTrigger, SidecarFolder: true})
Expand Down
38 changes: 38 additions & 0 deletions internal/autoscan/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,3 +921,41 @@ func TestPollNowStillSkipsWhenDisabledAndWebhookSources(t *testing.T) {
t.Fatalf("PollNow must not poll webhook sources")
}
}

// hiddenVanishedResolver answers like the real resolver for a deleted hidden
// file: the path is missing, and the vanished-file retry rejects it as hidden.
type hiddenVanishedResolver struct{ fakeResolver }

func (hiddenVanishedResolver) Resolve(context.Context, scantrigger.Request) (*scantrigger.Target, error) {
return nil, &scantrigger.RequestError{Status: 400, Code: "bad_request", Message: "Path does not exist", Reason: scantrigger.ReasonPathMissing}
}

func (hiddenVanishedResolver) ResolveVanishedFile(context.Context, string, string) (*scantrigger.Target, error) {
return nil, &scantrigger.RequestError{Status: 400, Code: "bad_request", Message: "Hidden files are not scanned", Reason: scantrigger.ReasonPathIgnored}
}

func (hiddenVanishedResolver) ResolveVanishedPath(context.Context, string, string) (*scantrigger.Target, error) {
return nil, &scantrigger.RequestError{Status: 400, Code: "bad_request", Message: "Hidden files are not scanned", Reason: scantrigger.ReasonPathIgnored}
}

// A legacy change in a deleted hidden folder is ignored, and its library
// counts as matched: scans skip hidden folders.
func TestResolveAndClaimRecordsVanishedHiddenFolderAsIgnored(t *testing.T) {
svc := NewService(&fakeStore{}, nil, passthroughConnRes{}, hiddenVanishedResolver{}, nil, nil, nil)
records := make([]ChangeRecord, 1)
_, _, resolvedAny, _ := svc.resolveAndClaim(t.Context(), []Change{{SourcePath: "/mnt/media/.incoming/Film.mkv", Scope: ChangeScopeAuto}}, records, time.Minute)
if !resolvedAny || records[0].Outcome != ChangeOutcomeIgnored || records[0].Reason != string(scantrigger.ReasonPathIgnored) {
t.Fatalf("resolvedAny=%v outcome=%q reason=%q, want true ignored/path_ignored", resolvedAny, records[0].Outcome, records[0].Reason)
}
}

// A deleted hidden file is ignored, as it is while it exists, not unresolved.
func TestResolveChangeRecordsVanishedHiddenFileAsIgnored(t *testing.T) {
svc := NewService(&fakeStore{}, nil, passthroughConnRes{}, hiddenVanishedResolver{}, nil, nil, nil)
var rec ChangeRecord
var stats resolveStats
target, _ := svc.resolveChange(t.Context(), Change{SourcePath: "/mnt/media/Film/._Film.mkv", Scope: ChangeScopeFile}, &stats, &rec)
if target != nil || rec.Outcome != ChangeOutcomeIgnored || rec.Reason != string(scantrigger.ReasonPathIgnored) {
t.Fatalf("target=%v outcome=%q reason=%q, want ignored/path_ignored", target, rec.Outcome, rec.Reason)
}
}
4 changes: 2 additions & 2 deletions internal/scanner/audio_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
var audioExtensions = mediacontainer.AudioExtensions()

// SupportsAudioFile reports whether the given path uses a recognized audio
// file extension.
// file extension and is not hidden (SkippedFileName).
func SupportsAudioFile(filePath string) bool {
if filePath == "" {
if filePath == "" || SkippedFileName(filePath) {
return false
}
return audioExtensions[strings.ToLower(filepath.Ext(filePath))]
Expand Down
5 changes: 5 additions & 0 deletions internal/scanner/ebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ type parsedEbookCover struct {
Bytes []byte
}

// SupportsEbookFile reports whether the given path uses a recognized ebook
// or comic file extension and is not hidden (SkippedFileName).
func SupportsEbookFile(filePath string) bool {
if SkippedFileName(filePath) {
return false
}
if strings.HasSuffix(strings.ToLower(filePath), ".fb2.zip") {
return true
}
Expand Down
13 changes: 13 additions & 0 deletions internal/scanner/ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ const (
siloIgnoreFileName = ".siloignore"
)

// IsIgnoreFile reports whether name (a base name) is one of the ignore files
// above. They are hidden files the scan reads as rules rather than skipping.
func IsIgnoreFile(name string) bool {
return name == ignoreFileName || name == ignoreMarkerNoMedia || name == siloIgnoreFileName
}

// HiddenFile reports whether a change to path concerns a hidden file scans
// skip (SkippedFileName), so it needs no scan. Ignore files are hidden too,
// but scans read them, so a change to one is not a hidden-file change.
func HiddenFile(path string) bool {
return SkippedFileName(path) && !IsIgnoreFile(filepath.Base(path))
}

// ignoreRules is one parsed ignore file: the logical path of the directory it
// lives in plus its patterns. A .siloignore holds glob patterns
// (filepath.Match semantics, so `*` matches within one path segment and `/`
Expand Down
47 changes: 47 additions & 0 deletions internal/scanner/ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"os"
"path/filepath"
"slices"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -189,6 +190,8 @@ func TestAudiobookScanHonorsIgnoreFiles(t *testing.T) {

root := t.TempDir()
writeTestFile(t, filepath.Join(root, "Book One", "Chapter 01.mp3"), "test")
// A hidden file, such as the "._" file macOS writes beside each copy.
writeTestFile(t, filepath.Join(root, "Book One", "._Chapter 01.mp3"), "test")
writeTestFile(t, filepath.Join(root, "Book Two", "Chapter 01.mp3"), "test")
writeTestFile(t, filepath.Join(root, "Book Two", ".ignore"), "")
writeTestFile(t, filepath.Join(root, "sample", "Sample.mp3"), "test")
Expand Down Expand Up @@ -332,3 +335,47 @@ func TestIgnoreFilePatternsAtLibraryRootSkipOnlyMatches(t *testing.T) {
t.Fatalf("a root .ignore with patterns must not skip the root: skipped=%v err=%v", skipped, err)
}
}

// Hidden files are skipped like hidden directories: macOS writes an
// AppleDouble "._" file beside every file it copies to a network share, with
// the same extension. __MACOSX folders, left by unzipping a macOS archive,
// are skipped too.
func TestHiddenFilesAreSkipped(t *testing.T) {
t.Parallel()

for _, tc := range []struct{ libraryType, ext string }{
{"movies", ".mkv"},
{"ebooks", ".epub"},
} {
root := t.TempDir()
writeTestFile(t, filepath.Join(root, "Alpha (2020)", "Alpha (2020)"+tc.ext), "x")
writeTestFile(t, filepath.Join(root, "Alpha (2020)", "._Alpha (2020)"+tc.ext), "x")
writeTestFile(t, filepath.Join(root, ".Beta (2021)"+tc.ext), "x")
writeTestFile(t, filepath.Join(root, "__MACOSX", "Gamma (2022)", "Gamma (2022)"+tc.ext), "x")

assertFilePaths(t, collectTestFilePaths(t, root, tc.libraryType), root, []string{
"Alpha (2020)/Alpha (2020)" + tc.ext,
})
}
}

// A hidden file is never a local metadata sidecar, so adding or removing a
// macOS "._" copy of a poster or NFO does not change what metadata compares.
func TestHiddenFilesAreNotSidecars(t *testing.T) {
t.Parallel()

root := t.TempDir()
movie := filepath.Join(root, "Alpha (2020)")
writeTestFile(t, filepath.Join(movie, "Alpha (2020).mkv"), "x")
writeTestFile(t, filepath.Join(movie, "poster.jpg"), "x")
writeTestFile(t, filepath.Join(movie, "._poster.jpg"), "x")
writeTestFile(t, filepath.Join(movie, "._movie.nfo"), "x")

_, _, sidecars, err := collectLogicalFilePathsAndSidecars(t.Context(), []string{root}, "movies", []string{root})
if err != nil {
t.Fatal(err)
}
if got := sidecars[movie]; !slices.Equal(got, []string{"poster.jpg"}) {
t.Fatalf("sidecars = %v, want [poster.jpg]", got)
}
}
Loading
Loading