Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise( function(resolve, reject) {
fs.access(source, sourcePermissions) // Can Read Source?
.then( () => {
fs.access(nodePath.dirname(destination), fs.constants.W_OK) // Can Write Target Parent?
.then( () => {
fs.access(destination, fs.constants.W_OK) // does the Target already exists?
.then( () => {
debugger
if(clobber) {
resolve() // im allowed to overwrite the existing destionation
} else {
console.log('reject')
reject({ // not allowed to overwrite
code: c.ERROR_DEST_ALREADY_EXISTS
})
}
})
.catch((err) => {
.then( () => {
fs.access(nodePath.dirname(destination), fs.constants.W_OK) // Can Write Target Parent?
.then( () => {
fs.access(destination, fs.constants.W_OK) // does the Target already exists?
.then( () => {
debugger
if(clobber) {
resolve() // im allowed to overwrite the existing destionation
} else {
console.log('reject')
reject({ // not allowed to overwrite
code: c.ERROR_DEST_ALREADY_EXISTS
})
}
})
.catch((err) => {
if(err.code == c.ERROR_NOT_EXISTS)
{ resolve() } // Destination does not exists -> free space -> go
resolveEpub(id, url) {
const bookPath = path.join(this.repo, id);
return fs.access(bookPath, fs.constants.R_OK)
.then(
() => bookPath,
// If the book doesn't exist, download it:
() => this.downloadEpub(bookPath, url)
);
}
const getPathForAsset = curryN(3, wrap(function *(type, dir, config) {
const exts = extensionsForAsset(type, config);
for (const ext of exts) {
const fpath = join(dir, `${type}.${ext}`);
try {
yield access(fpath, R_OK);
} catch (err) {
continue;
}
return fpath;
}
return null;
}));
async function exists (path) {
try {
await fs.access(path)
return true
} catch (error) {
return false
}
}
export const readAsset = wrap(function *(name) {
const fpath = getAssetPath(name);
try {
yield access(fpath, R_OK);
return yield readToStr(fpath);
} catch (err) {
return null;
}
});
return new Promise((resolve, reject) => {
fs.access(this.basedir, (accessError) => {
if (accessError) {
fs.mkdir(this.basedir, 0o777, (error) => {
if (error) {
reject(error);
} else {
resolve(x);
}
});
} else {
resolve(x);
}
});
});
}
async _addCache() {
const fpath = path.join(this.package.app.cache.dest, this.id)
const dir = path.dirname(fpath)
try {
await access(dir)
} catch (err) {
await mkdirp(dir)
}
await writeFile(`${fpath}.cache`, JSON.stringify(this.cache))
}