convert more execSync to async

This commit is contained in:
Girish Ramakrishnan
2024-02-20 23:09:49 +01:00
parent b51071155a
commit 9b94cf18d0
15 changed files with 71 additions and 72 deletions

View File

@@ -22,6 +22,7 @@ const assert = require('assert'),
ProgressStream = require('../progress-stream.js'),
promiseRetry = require('../promise-retry.js'),
safe = require('safetydance'),
shell = require('../shell.js'),
storage = require('../storage.js'),
stream = require('stream'),
syncer = require('../syncer.js'),
@@ -109,17 +110,15 @@ async function saveFsMetadata(dataLayout, metadataFile) {
// we assume small number of files. spawnSync will raise a ENOBUFS error after maxBuffer
for (let lp of dataLayout.localPaths()) {
const emptyDirs = safe.child_process.execSync(`find ${lp} -type d -empty`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 80 });
if (emptyDirs === null) throw new BoxError(BoxError.FS_ERROR, `Error finding empty dirs: ${safe.error.message}`);
if (emptyDirs.length) metadata.emptyDirs = metadata.emptyDirs.concat(emptyDirs.trim().split('\n').map((ed) => dataLayout.toRemotePath(ed)));
const emptyDirs = await shell.promises.exec('saveFsMetadata', `find ${lp} -type d -empty`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 80 });
metadata.emptyDirs = metadata.emptyDirs.concat(emptyDirs.trim().split('\n').map((ed) => dataLayout.toRemotePath(ed)));
const execFiles = safe.child_process.execSync(`find ${lp} -type f -executable`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 80 });
if (execFiles === null) throw new BoxError(BoxError.FS_ERROR, `Error finding executables: ${safe.error.message}`);
if (execFiles.length) metadata.execFiles = metadata.execFiles.concat(execFiles.trim().split('\n').map((ef) => dataLayout.toRemotePath(ef)));
const execFiles = await shell.promises.exec('saveFsMetadata', `find ${lp} -type f -executable`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 80 });
metadata.execFiles = metadata.execFiles.concat(execFiles.trim().split('\n').map((ef) => dataLayout.toRemotePath(ef)));
const symlinks = safe.child_process.execSync(`find ${lp} -type l`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 30 });
if (symlinks === null) throw new BoxError(BoxError.FS_ERROR, `Error finding symlinks: ${safe.error.message}`);
if (symlinks.length) metadata.symlinks = metadata.symlinks.concat(symlinks.trim().split('\n').map((sl) => {
const symlinks = await shell.promises.exec('safeFsMetadata', `find ${lp} -type l`, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 30 });
console.log(symlinks);
metadata.symlinks = metadata.symlinks.concat(symlinks.trim().split('\n').map((sl) => {
const target = safe.fs.readlinkSync(sl);
return { path: dataLayout.toRemotePath(sl), target };
}));