Skip to content

Commit 7feaaf6

Browse files
committed
add prev check to incrementName()
1 parent 7d79ef2 commit 7feaaf6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ write.stream = (filepath, options) => {
146146
const incrementName = destpath => {
147147
let file = { ...path.parse(destpath), path: destpath };
148148
let name = file.name;
149+
let prev;
149150
let n = 1;
150151

151-
while (fs.existsSync(file.path)) {
152+
while (prev !== file.path && fs.existsSync(file.path)) {
153+
prev = file.path;
152154
file.path = path.join(file.dir, `${name} (${++n})${file.ext}`);
153155
}
154156

0 commit comments

Comments
 (0)