Skip to content

Fix increment:true creating foo (2).txt on empty directories - #15

Open
dyk1454683243-sudo wants to merge 1 commit into
jonschlinkert:masterfrom
dyk1454683243-sudo:cursor/fix-increment-empty-dir-62e2
Open

dyk1454683243-sudo wants to merge 1 commit into
jonschlinkert:masterfrom
dyk1454683243-sudo:cursor/fix-increment-empty-dir-62e2

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

write.sync('foo.txt', 'some data', { increment: true }) on an empty directory currently creates foo (2).txt on Windows instead of foo.txt.

add-filename-increment only checks whether the destination exists when options.fs === true. Without that, the Windows formatter starts at 2 and always emits foo (2).txt. The workaround in #11 ({ increment: true, fs: true }) works for that reason.

Change

When options.increment is set, pass fs: true into add-filename-increment so existence checks run. Default non-increment writes are unchanged. The caller’s options object is no longer mutated.

Tests

  • Empty directory + platform: 'win32' keeps foo.txt for async, sync, and stream
  • Empty directory without a platform override keeps the original name
  • An existing dest still increments to foo (2).txt / foo (3).txt

Fixes #11

add-filename-increment only checks existence when `fs: true`.
Without that, Windows incrementing starts at 2, so the first
write with `{ increment: true }` created `foo (2).txt` instead
of `foo.txt`. Pass `fs: true` when incrementing and leave
non-increment writes unchanged.

Fixes jonschlinkert#11

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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.

increment doesn't work as expected

2 participants