Commit 005ba59
Fix ReplaceDbNameInFile to only replace filename, not directory path
Fixes #9656
The issue was that ReplaceDbNameInFile was replacing the database name in the full file path (including directory), which caused the directory path to be incorrectly modified. This led to 'file already exists and owned by another database' errors because the code would look in the wrong directory or create invalid paths.
The fix moves the database name replacement to apply only to the basename (filename without directory), after extracting the directory path and before reconstructing the full path. This ensures the directory structure remains intact while only the filename gets the database name replaced.
Changes: Modified Format-DbaBackupInformation.ps1 to replace database name in basename only, not full path. Added regression test for #9656 to prevent this issue from recurring.
Co-authored-by: Chrissy LeMaire <potatoqualitee@users.noreply.github.com>1 parent f1ed5db commit 005ba59
File tree
2 files changed
+21
-3
lines changed- public
- tests
2 files changed
+21
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | 189 | | |
193 | 190 | | |
194 | 191 | | |
195 | 192 | | |
196 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
223 | 241 | | |
224 | 242 | | |
225 | 243 | | |
| |||
0 commit comments