storage: make exists async
This commit is contained in:
@@ -159,18 +159,17 @@ function download(apiConfig, sourceFilePath, callback) {
|
||||
callback(null, fileStream);
|
||||
}
|
||||
|
||||
function exists(apiConfig, sourceFilePath, callback) {
|
||||
async function exists(apiConfig, sourceFilePath) {
|
||||
assert.strictEqual(typeof apiConfig, 'object');
|
||||
assert.strictEqual(typeof sourceFilePath, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
// do not use existsSync because it does not return EPERM etc
|
||||
if (!safe.fs.statSync(sourceFilePath)) {
|
||||
if (safe.error && safe.error.code === 'ENOENT') return callback(null, false);
|
||||
if (safe.error) return callback(new BoxError(BoxError.EXTERNAL_ERROR, `Exists ${sourceFilePath}: ${safe.error.message}`));
|
||||
if (safe.error && safe.error.code === 'ENOENT') return false;
|
||||
if (safe.error) throw new BoxError(BoxError.EXTERNAL_ERROR, `Exists ${sourceFilePath}: ${safe.error.message}`);
|
||||
}
|
||||
|
||||
callback(null, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
function listDir(apiConfig, dir, batchSize, iteratorCallback, callback) {
|
||||
|
||||
Reference in New Issue
Block a user