storage: make exists async

This commit is contained in:
Girish Ramakrishnan
2022-04-14 08:07:03 -05:00
parent 11f7be2065
commit d54c03f0a0
6 changed files with 28 additions and 39 deletions

View File

@@ -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) {