Commit cc9ed04
Support multiple root directories for monitoring (#80)
Sonarr users often have multiple library root folders, and using a
common parent directory risks processing Radarr (or other) folders
unintentionally. This adds support for configuring multiple root
directories to monitor independently.
## Config changes
`REWRITE_ROOT_DIR` (single path) remains fully backward compatible. New
`REWRITE_ROOT_DIRS` takes priority and accepts a comma-separated list:
```bash
REWRITE_ROOT_DIRS=/tv,/anime
```
The `rewrite_root_dir: Path` field is replaced by `rewrite_root_dirs:
list[Path]`.
## Component updates
- **`file_scanner`** — iterates over all root dirs per scan cycle;
checks `stop_event` before each root dir and `break`s the inner file
loop on signal
- **`file_monitor`** — registers a separate watchdog watch per root dir
- **`file_utils`** — adds `find_root_dir_for_file(file_path, root_dirs)`
to resolve which root dir owns a given file path
- **`backup_utils`** — backups now use the file's full absolute path
(minus the leading `/`) as the storage key, e.g. `/tv/Show A/tvshow.nfo`
→ `<BACKUP_DIR>/tv/Show A/tvshow.nfo`. This guarantees no collision when
files from different root dirs share the same relative path. The
`root_dir` parameter has been removed from all backup functions. An
optional `root_dirs` parameter provides backward-compatible fallback:
when the new-format path is not found, functions automatically search
the legacy root-dir-relative paths so existing backups from older
versions are still found and restored without any migration step. New
backups are always written in the new format.
- **`metadata_processor` / `image_processor`** — pass
`rewrite_root_dirs` to backup calls to enable the legacy fallback
- **`rollback_service`** — reconstructs the original absolute path
directly from the backup path (`Path("/") /
backup_file.relative_to(backup_dir)`); falls back to the legacy
root-dir-relative search for backups created by older versions
- **`main` / `rewrite_service`** — log each monitored directory at
startup
## Documentation
Updated `README.md` with:
- `REWRITE_ROOT_DIRS` configuration option and backward-compat note for
`REWRITE_ROOT_DIR`
- Multi-directory Docker run and Docker Compose examples
- Backup directory structure explanation, including
backward-compatibility note for old-format backups
- Updated startup log, volume mapping, and rollback examples
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: kfstorm <3626358+kfstorm@users.noreply.github.com>1 parent fb94675 commit cc9ed04
22 files changed
Lines changed: 1154 additions & 439 deletions
File tree
- src/sonarr_metadata_rewrite
- tests
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
| 97 | + | |
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
98 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
99 | 105 | | |
100 | 106 | | |
101 | 107 | | |
| |||
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
124 | 137 | | |
125 | 138 | | |
126 | 139 | | |
| |||
198 | 211 | | |
199 | 212 | | |
200 | 213 | | |
201 | | - | |
| 214 | + | |
202 | 215 | | |
203 | 216 | | |
204 | 217 | | |
205 | | - | |
206 | | - | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
207 | 221 | | |
208 | 222 | | |
209 | 223 | | |
| |||
229 | 243 | | |
230 | 244 | | |
231 | 245 | | |
232 | | - | |
| 246 | + | |
| 247 | + | |
233 | 248 | | |
234 | 249 | | |
235 | 250 | | |
| |||
282 | 297 | | |
283 | 298 | | |
284 | 299 | | |
285 | | - | |
| 300 | + | |
286 | 301 | | |
287 | | - | |
| 302 | + | |
| 303 | + | |
288 | 304 | | |
289 | 305 | | |
290 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
5 | 26 | | |
6 | 27 | | |
7 | 28 | | |
8 | 29 | | |
9 | 30 | | |
10 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
11 | 55 | | |
12 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
13 | 59 | | |
14 | 60 | | |
15 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
16 | 65 | | |
17 | | - | |
| 66 | + | |
18 | 67 | | |
19 | | - | |
| 68 | + | |
| 69 | + | |
20 | 70 | | |
21 | 71 | | |
22 | 72 | | |
| |||
26 | 76 | | |
27 | 77 | | |
28 | 78 | | |
29 | | - | |
30 | | - | |
31 | | - | |
| 79 | + | |
| 80 | + | |
32 | 81 | | |
33 | | - | |
34 | 82 | | |
35 | 83 | | |
36 | 84 | | |
37 | | - | |
38 | | - | |
39 | 85 | | |
40 | 86 | | |
41 | 87 | | |
42 | 88 | | |
43 | | - | |
44 | 89 | | |
45 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
46 | 105 | | |
47 | 106 | | |
48 | 107 | | |
49 | | - | |
50 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
51 | 118 | | |
52 | 119 | | |
53 | | - | |
| 120 | + | |
54 | 121 | | |
55 | | - | |
| 122 | + | |
| 123 | + | |
56 | 124 | | |
57 | 125 | | |
58 | 126 | | |
| |||
63 | 131 | | |
64 | 132 | | |
65 | 133 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 134 | + | |
| 135 | + | |
69 | 136 | | |
70 | | - | |
71 | 137 | | |
72 | 138 | | |
73 | 139 | | |
74 | | - | |
75 | | - | |
76 | 140 | | |
77 | 141 | | |
78 | 142 | | |
79 | 143 | | |
80 | | - | |
81 | 144 | | |
82 | 145 | | |
83 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
84 | 162 | | |
85 | | - | |
86 | | - | |
87 | 163 | | |
88 | 164 | | |
89 | 165 | | |
90 | 166 | | |
91 | 167 | | |
92 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
93 | 171 | | |
94 | 172 | | |
95 | 173 | | |
96 | 174 | | |
97 | 175 | | |
98 | 176 | | |
99 | | - | |
| 177 | + | |
100 | 178 | | |
101 | 179 | | |
102 | 180 | | |
103 | 181 | | |
104 | | - | |
| 182 | + | |
105 | 183 | | |
106 | | - | |
| 184 | + | |
107 | 185 | | |
108 | 186 | | |
109 | 187 | | |
110 | 188 | | |
111 | | - | |
112 | | - | |
| 189 | + | |
| 190 | + | |
113 | 191 | | |
114 | 192 | | |
115 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
23 | 31 | | |
24 | 32 | | |
25 | 33 | | |
| |||
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | | - | |
37 | | - | |
| 44 | + | |
| 45 | + | |
38 | 46 | | |
39 | 47 | | |
40 | 48 | | |
| |||
88 | 96 | | |
89 | 97 | | |
90 | 98 | | |
91 | | - | |
92 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
93 | 104 | | |
94 | 105 | | |
95 | 106 | | |
| |||
100 | 111 | | |
101 | 112 | | |
102 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
103 | 127 | | |
104 | 128 | | |
105 | 129 | | |
| |||
0 commit comments