Skip to content

Flatten a backup's source path on Windows too - #125

Merged
fylorn merged 1 commit into
mainfrom
fix/windows-backup-path
Sep 23, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/windows-backup-path

Conversation

@fylorn

@fylorn fylorn commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

The second real bug the Windows CI job found, and worse than the first.

The source path is squashed into one file name so a backup says whose it is — /Users/x/.claude/settings.json becomes Users%x%.claude%settings.json. It only replaced /.

On Windows the separator is \, so the name kept its backslashes — and Path::join given an absolute path discards the base entirely. The "file inside the backup directory" quietly became the user's own configuration file.

What happened next was create_new, reporting that the file already exists. That complaint is the thing that saved us. Without it the backup step would have written backup text over the user's configuration — and not damaging other people's files is the entire reason this module exists.

The comment above that call reads "the directory was just created, so there should be no file by this name; if there is, better to fail than overwrite." That should is a certainty on the other platform.

The colon goes too: the one in C: is not legal in a Windows file name.

The part worth keeping

The test runs on macOS and fails against the old implementation. I put the old code back to confirm it — FAILED.

A \ separator survives a string replacement of / on any platform. This never needed a Windows machine to be caught. It was caught by one only because nothing had ever asked the question.

Verified

clippy clean workspace-wide, full test suite green (98 in tw-adopt), and the new test verified to fail against the previous implementation rather than merely passing against the new one.

Found by the Windows CI job in #119, which is stacked on this.

🤖 Generated with Claude Code

The source path is squashed into one file name so a backup says whose it
is. It only replaced `/`. On Windows the separator is `\`, so the name
kept its backslashes -- and `Path::join` given an absolute path discards
the base entirely. The "file inside the backup directory" quietly became
the user's own configuration file.

What happened next was `create_new`, reporting that the file already
exists. That complaint is the thing that saved us: without it the backup
step would have written backup text over the user's configuration, and not
damaging other people's files is the entire reason this module exists.

The colon goes too. The one in `C:` is not legal in a Windows file name.

The test runs on macOS and fails against the old implementation, which is
the part worth keeping: a `\` separator survives string replacement of `/`
on any platform, so this never needed a Windows machine to be caught. It
was caught by one only because nothing had asked.

Found by the Windows CI job in #119.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the fix/windows-backup-path branch from b77d1ca to 8ca5ae2 Compare September 23, 2026 06:40
@fylorn
fylorn merged commit b7a6636 into main Sep 23, 2026
1 check passed
@fylorn
fylorn deleted the fix/windows-backup-path branch September 23, 2026 06:46
@fylorn fylorn mentioned this pull request Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant