How to use the fs.lstatSync function in fs

To help you get started, we’ve selected a few fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meboHQ / mebo / test / testutils / Actions / File / Delete.js View on Github external
return (async () => {

      const deleteAction = Mebo.Action.create('file.delete');
      deleteAction.input('file').setValue(filePath);

      await deleteAction.run();

      // in case the file delete has worked, the stats will throw an exception when
      // querying it from a file that does not exist
      try{
        fs.lstatSync(filePath);
      }
      catch(err){
        return true;
      }

      return false;

    })();
  });
github jamesshore / lets_code_javascript / node_modules / shelljs / src / cp.js View on Github external
// Create the directory where all our junk is moving to; read the mode of the
  // source directory and mirror it
  try {
    var checkDir = fs.statSync(sourceDir);
    fs.mkdirSync(destDir, checkDir.mode);
  } catch (e) {
    // if the directory already exists, that's okay
    if (e.code !== 'EEXIST') throw e;
  }

  var files = fs.readdirSync(sourceDir);

  for (var i = 0; i < files.length; i++) {
    var srcFile = sourceDir + '/' + files[i];
    var destFile = destDir + '/' + files[i];
    var srcFileStat = fs.lstatSync(srcFile);

    var symlinkFull;
    if (opts.followsymlink) {
      if (cpcheckcycle(sourceDir, srcFile)) {
        // Cycle link found.
        console.error('Cycle link found.');
        symlinkFull = fs.readlinkSync(srcFile);
        fs.symlinkSync(symlinkFull, destFile, os.platform() === 'win32' ? 'junction' : null);
        continue;
      }
    }
    if (srcFileStat.isDirectory()) {
      /* recursion this thing right on back. */
      cpdirSyncRecursive(srcFile, destFile, currentDepth, opts);
    } else if (srcFileStat.isSymbolicLink() && !opts.followsymlink) {
      symlinkFull = fs.readlinkSync(srcFile);
github jamesshore / lets_code_javascript / node_modules / shelljs / src / mkdir.js View on Github external
dirs.forEach(function (dir) {
    try {
      fs.lstatSync(dir);
      if (!options.fullpath) {
        common.error('path already exists: ' + dir, { continue: true });
      }
      return; // skip dir
    } catch (e) {
      // do nothing
    }

    // Base dir does not exist, and no -p option given
    var baseDir = path.dirname(dir);
    if (!fs.existsSync(baseDir) && !options.fullpath) {
      common.error('no such file or directory: ' + baseDir, { continue: true });
      return; // skip dir
    }

    try {
github saskodh / framework / src / lib / decorators / ComponentScanDecorator.ts View on Github external
private static * getModulesStartingFrom(path: string) {
        if (!fileSystem.lstatSync(path).isDirectory()) {
            throw new Error(`Given path must be a valid directory. Path: ${path}`);
        }

        let files = fileSystem.readdirSync(path);
        for (let fileName of files) {
            let filePath = path_module.join(path, fileName);
            let lstat = fileSystem.lstatSync(filePath);

            // if it's JavaScript file load it
            if (lstat.isFile() && path_module.extname(fileName) === '.js') {
                logger.debug(`Loading dynamically by @ComponentScan: ${fileName} (${filePath})`);
                yield RequireUtils.require(filePath);
            }

            if (lstat.isDirectory()) {
                yield * this.getModulesStartingFrom(filePath);
github sensepost / wsproxy / wsproxy.js View on Github external
var WebSocketClient = require('websocket').client;
var processor = require('./wsprocessor.js')
var config = require('./config')

var verbose = config.verbose


var getTimeStamp = processor.getTimeStamp;


if (config.logStdOutToFile) {
    var fs = require('fs');
    var path = require('path');
    if (!fs.existsSync(config.logStdOutFilePath)) 
        fs.mkdirSync(config.logStdOutFilePath)
    if (!fs.lstatSync(config.logStdOutFilePath).isDirectory()) {
        console.log('Log file output path exists and is not a directory.');
        process.exit(1);
    }
    var logFile = path.join(config.logStdOutFilePath,getTimeStamp()+'_wsproxy.txt');

    doLog = function(log){
        data = log.map(function(x){return (x)?x.toString():''}).join(' ');
        console.log(getTimeStamp(),data);
        fs.appendFileSync(logFile, getTimeStamp() + ' ' + data + '\n');
    }

} else {
    doLog = function(log){
        data = log.map(function(x){return (x)?x.toString():''}).join(' ');
        console.log(getTimeStamp(), data);
    }
github bladechapman / TinyRadio / tools / dj.js View on Github external
function filterDirectory(path) {
        var files = [];
        var ret = [];

        try {
            var stats = fs.lstatSync(path);
            if (stats.isDirectory()) { files = recursiveReaddirSync(path); }
            else { except(); }
        }
        catch (err) { except(); }
        function except() {
            console.log("Looks like you don't have any sounds. Try adding some to " + path);
            try { fs.mkdirSync(path); }
            catch(err) { console.log("Could not create " + path + ". This directory may already exist, but with no sounds."); }
            process.exit();
        }

        if (files.length === 0) { except(); }
        files.forEach(function(element) {
            var path_components = element.split('.');
            if(fs.lstatSync(element).isFile() && path_components[path_components.length - 1] in type_whitelist) {
                ret.push(element);
github apache / cordova-cli / spec / cordova-cli / create.spec.js View on Github external
it('should create a cordova project in the specified dir with specified name and id if provided', function() {
        cordova.create(tempDir, "birdy.nam.nam", "numnum");

        expect(fs.lstatSync(path.join(tempDir, '.cordova', 'config.json')).isFile()).toBe(true);

        var config = fs.readFileSync(util.projectConfig(tempDir)).toString('utf8');
        expect(config).toMatch(/numnum<\/name>/);
        expect(config).toMatch(/id="birdy\.nam\.nam"/);
    });
});
github askwonder / wonqa / src / validate.js View on Github external
const validateNginxConf = (servers, configurationPath) => {
  validateNginxServersConf(servers);
  if (configurationPath) {
    const stats = fs.lstatSync(configurationPath);
    if (!stats.isFile()) {
      throw new Error('nginx.configurationPath is not a path to a file');
    }
    const config = fs.readFileSync(configurationPath);
    const expectedConfigs = [
      'http {',
      'ssl_certificate     /etc/ssl/fullchain1.pem;',
      'ssl_certificate_key /etc/ssl/privkey1.pem;',
    ];
    expectedConfigs.forEach((el) => {
      if (!config.includes(el)) {
        throw new Error(`NGINX configuration missing '${el}'`);
      }
    });
  }
};
github megahertz / electron-simple-publisher / src / transport / local.js View on Github external
.forEach((file) => {
      fs.lstatSync(file).isDirectory() ? rmDir(file) : fs.unlinkSync(file);
    });
  fs.rmdirSync(dirPath);
github zbo14 / constellate / lib / swarm-node.js View on Github external
this.upload = (path) => {
        let cmd = 'swarm ';
        if (fs.lstatSync(path).isDirectory()) {
            cmd += '--recursive ';
        }
        if (!running) {
            cmd += '--bzzapi http://swarm-gateways.net/ ';
        }
        cmd += 'up ' + path;
        return new Promise((resolve, reject) => {
            exec(cmd, (err, stdout, stderr) => {
                if (err) return reject(err);
                if (stderr) return reject(stderr);
                if (stdout) resolve(stdout);
            });
        });
    }
}

fs

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis