Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
await new Promise(resolve => {
nullServer.listen(0, "0.0.0.0", () => resolve());
});
}
if(nullServer !== null) {
options.nullServer = true;
const a = nullServer.address();
serverAddress = `${a.address}:${a.port}`;
}
// Gather files
const files = [];
const stat = await fs.stat(filePath);
if(stat.isDirectory()) {
await helpers.readDir(filePath, f => files.push(f.path));
}
else {
files.push(filePath);
}
// Validate files
const verBuf = Buffer.alloc(consts.VERSION_SIZE, 'ascii');
for(let i = 0; i < files.length; i++) {
const fd = await fs.open(files[i], "r");
await fs.read(fd, verBuf, 0, consts.VERSION_SIZE, 0);
if(helpers.readUInt32(verBuf) !== consts.PROTOCOL_VERSION) {
if(options.verbose) {
console.log(`Skipping unrecognized file ${files[i]}`);
}
return new Promise((resolve, reject) => {
// todo remove
const allowCreateFolder = false;
fs.stat(scriptPath, function(err1: any, stats1: any) {
if (err1) {
if (allowCreateFolder && 'ENOENT' === err1.code && 'js' !== path.extname(scriptPath)) {
const p = scriptPath.split(path.sep);
const newfolder = p.pop();
const _path = p.join(path.sep);
fs.stat(_path, (err2: any, stats2: any) => {
if (err2) {
if ('ENOENT' === err2.code) {
reject('can only create a single subfolder on a valid path');
} else {
reject(err2.message);
}
} else {
if (stats2.isDirectory()) {
if (newfolder) {
resolve(path.join(_path, newfolder));
}
// copy files
{
const FILES = SRC_ENTRIES.filter(e => e.stat.isFile());
for (const F of FILES) {
let copyFile = true;
let operationStart = 'Copy';
let operationFinished = 'copied';
const DEST_PATH = path.resolve(
path.join(dest, F.name)
);
if (await exists(DEST_PATH)) {
const DEST_STAT = await fs.stat(DEST_PATH);
if (DEST_STAT.isFile()) {
copyFile = !this._areFilesEqual(F.stat, DEST_STAT);
operationStart = 'Update';
operationFinished = 'updated';
}
}
if (copyFile) {
const REL_SRC_PATH = path.relative(rootDir, F.path);
await withSpinnerAsync(`🚛 ${operationStart} ${colorize(REL_SRC_PATH)} ...`, async (spinner) => {
await fs.copy(
F.path, DEST_PATH,
{
overwrite: true,
return fsPath;
} else {
throw new UserCancelledError();
}
}
} else if (response === browse) {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://docs.mongodb.com/manual/installation/'));
// default down to cancel error because MongoShell.create errors out if undefined is passed as the shellPath
}
throw new UserCancelledError();
}
} else {
// User has specified the path or command. Sometimes they set the folder instead of a path to the file, let's check that and auto fix
if (await fse.pathExists(shellPathSetting)) {
let stat = await fse.stat(shellPathSetting);
if (stat.isDirectory()) {
return path.join(shellPathSetting, mongoExecutableFileName);
}
}
return shellPathSetting;
}
}
}
async resolveDotGitDir() {
try {
await fs.stat(this.workingDir); // fails if folder doesn't exist
const output = await this.exec(['rev-parse', '--resolve-git-dir', path.join(this.workingDir, '.git')]);
const dotGitDir = output.trim();
return toNativePathSep(dotGitDir);
} catch (e) {
return null;
}
}
async() => {
try
{
if(nPackageJSONModificationTime !== (await fs.stat(strPackageJSONPath)).mtime.getTime())
{
nPackageJSONModificationTime = (await fs.stat(strPackageJSONPath)).mtime.getTime();
strVersionNew = JSON.parse(await fs.readFile(strPackageJSONPath, "utf8")).version;
}
if(strVersionNew !== strVersion)
{
clearInterval(nIntervalID);
console.log(`
Updated.
Detected new version ${strVersionNew}.
Old version ${strVersion}.
Attempting to exit gracefully to allow starting with new version.
`.replace(/^\t+/gm, ""));
await this.gracefulExit(null);
}
async function newGoal(type, goal): Promise {
checkConf();
const date = moment().format("MMMDDYYYYHHmm");
const file = getFileName(type, goal);
const filePath = getFileName(type);
const completedFile = getFileName(path.join("completed", type, date), goal);
fs.stat(completedFile, async function(err, stat) {
if (err == null) {
//file exists
console.log("Moving goal from completed to " + type);
fs.rename(file, completedFile);
} else if (err.code == "ENOENT") {
fs.stat(file, async function(err2, stat2) {
if (err2 == null) {
//file exists
console.log("Goal already exists");
} else if (err2.code == "ENOENT") {
fs.ensureDirSync(filePath);
//file does not exist
fs.close(fs.openSync(file, "w"));
}
});
}
async function isPathToFile (filePath) {
const stat = await fs.stat(filePath)
return stat.isFile()
}
async watchForUpgrade(strPackageJSONPath)
{
assert(typeof strPackageJSONPath === "string");
if(this._bWatchingForUpgrade)
{
return;
}
this._bWatchingForUpgrade = true;
const strVersion = JSON.parse(await fs.readFile(strPackageJSONPath, "utf8")).version;
let nPackageJSONModificationTime = (await fs.stat(strPackageJSONPath)).mtime.getTime();
let strVersionNew = strVersion;
const nIntervalMilliseconds = 10 * 1000;
const nIntervalID = setInterval(
async() => {
try
{
if(nPackageJSONModificationTime !== (await fs.stat(strPackageJSONPath)).mtime.getTime())
{
nPackageJSONModificationTime = (await fs.stat(strPackageJSONPath)).mtime.getTime();
strVersionNew = JSON.parse(await fs.readFile(strPackageJSONPath, "utf8")).version;
}
if(strVersionNew !== strVersion)
{
public async cleanDirRecursive(dir: string) {
if (await fs.pathExists(dir)) {
for (const name of await fs.readdir(dir)) {
const filePath = path.join(dir, name);
if ((await fs.stat(filePath)).isDirectory()) {
await this.cleanDirRecursive(filePath);
if ((await fs.readdir(filePath)).length === 0) {
await fs.rmdir(filePath);
}
} else {
let ext = path.extname(filePath);
let baseName = path.basename(filePath, ext);
let subext = path.extname(baseName);
baseName = path.basename(baseName, subext);
const relativeToOut = path.dirname(path.relative(this.outPath, filePath));
const rootPath = path.join(this.rootPath, relativeToOut);
if (ext === ".lua") {
let exists = false;
exists = exists || (await fs.pathExists(path.join(rootPath, baseName) + subext + ".ts"));
exists = exists || (await fs.pathExists(path.join(rootPath, baseName) + subext + ".tsx"));
exists =