code cleanup
This commit is contained in:
parent
78ef651ca7
commit
e8cd664965
8 changed files with 362 additions and 406 deletions
15
src/fsutil.js
Normal file
15
src/fsutil.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// Returns a non-existing path in `base` named `name` (or `name (2)`, `name (3)`...).
|
||||
function dedupeDir(base, name) {
|
||||
const candidate = path.join(base, name)
|
||||
if (!fs.existsSync(candidate)) return candidate
|
||||
let n = 2
|
||||
while (fs.existsSync(path.join(base, `${name} (${n})`))) n++
|
||||
return path.join(base, `${name} (${n})`)
|
||||
}
|
||||
|
||||
module.exports = { dedupeDir }
|
||||
Loading…
Add table
Add a link
Reference in a new issue