Correct mkdir
This commit is contained in:
parent
ec8407c65d
commit
498f344e2e
1 changed files with 14 additions and 9 deletions
|
@ -8,14 +8,19 @@ const getChromeStoragePath = (storageType, extensionId) => {
|
|||
app.getPath('userData'), `/Chrome Storage/${extensionId}-${storageType}.json`)
|
||||
}
|
||||
|
||||
// recursively create directory and parent directories if needed
|
||||
const mkdirParent = (dirPath, mode, callback) => {
|
||||
fs.mkdir(dirPath, mode, error => {
|
||||
if (error && error.errno === 34) {
|
||||
fs.mkdirParent(path.dirname(dirPath), mode, callback)
|
||||
fs.mkdirParent(dirPath, mode, callback)
|
||||
const mkdirp = (dir, callback) => {
|
||||
fs.mkdir(dir, (error) => {
|
||||
if (error && error.code === 'ENOENT') {
|
||||
mkdirp(path.dirname(dir), (error) => {
|
||||
if (!error) {
|
||||
mkdirp(dir, callback)
|
||||
}
|
||||
})
|
||||
} else if (error && error.code === 'EEXIST') {
|
||||
callback(null)
|
||||
} else {
|
||||
callback(error)
|
||||
}
|
||||
callback && callback(error)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -32,8 +37,8 @@ const readChromeStorageFile = (storageType, extensionId, cb) => {
|
|||
const writeChromeStorageFile = (storageType, extensionId, data, cb) => {
|
||||
const filePath = getChromeStoragePath(storageType, extensionId)
|
||||
|
||||
mkdirParent(path.dirname(filePath), err => {
|
||||
if (err) { /* we just ignore the errors of mkdir or mkdirParent */ }
|
||||
mkdirp(path.dirname(filePath), err => {
|
||||
if (err) { /* we just ignore the errors of mkdir or mkdirp */ }
|
||||
fs.writeFile(filePath, data, cb)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue