Exemplo n.º 1
0
  it('writes file atime and mtime using the vinyl stat', function(done) {
    if (isWindows) {
      this.skip();
      return;
    }

    // Use the atime/mtime of this file to have proper resolution
    var atime = fs.lstatSync(__filename).atime;
    var mtime = fs.lstatSync(__filename).mtime;

    var file = new File({
      base: inputBase,
      path: inputPath,
      contents: new Buffer(contents),
      stat: {
        atime: atime,
        mtime: mtime,
      },
    });

    function assert() {
      var stats = fs.lstatSync(outputPath);

      expect(stats.atime.getTime()).toEqual(atime.getTime());
      expect(stats.mtime.getTime()).toEqual(mtime.getTime());
      expect(file.stat.mtime).toEqual(mtime);
      expect(file.stat.atime).toEqual(atime);
    };

    pipe([
      from.obj([file]),
      vfs.dest(outputBase, { cwd: __dirname }),
      concat(assert),
    ], done);
  });
Exemplo n.º 2
0
  // Iterate folders and push filepaths to track data workers
  generateLibrary(path) {
    let self = this;
    if (!fs.existsSync(path)) {
      console.log(path ," does not exist.");
      return;
    }
    // Dragging in a single file
    if (pathTools.extname(path) === ".mp3") {
      this.newTrackProcessor.push(path, function(err) {
        if (!err) {
          console.log('Processed ', path);
        } else {
          console.log(err);
        }
      });
      return;
    }

    let items = fs.readdirSync(path);
    for (let i = 0; i < items.length; i++) {
      let curFilePath = pathTools.join(path, items[i]);
      let curFileStats = fs.lstatSync(curFilePath);
      if (curFileStats.isDirectory()) {
        this.generateLibrary(curFilePath);
      } else if (pathTools.extname(curFilePath) === ".mp3") {
        this.newTrackProcessor.push(curFilePath, function(err) {
          if (!err) {
            console.log('Processed ', curFilePath);
          } else {
            console.log(err);
          }
        });
      }
    }
  }
Exemplo n.º 3
0
    var onEnd = function() {
      var stats = fs.lstatSync(expectedPath);

      expect(futimesSpy.calls.length).toEqual(0);
      expect(stats.mtime.getTime()).toBeGreaterThan(earlier);
      done();
    };
Exemplo n.º 4
0
  it('should pass through writes', function(done) {
    var expectedPath = path.join(__dirname, './fixtures/test.coffee');
    var expectedContent = fs.readFileSync(expectedPath);
    var files = [];
    var expectedFile = new File({
      base: __dirname,
      cwd: __dirname,
      path: expectedPath,
      contents: expectedContent,
      stat: fs.lstatSync(expectedPath),
    });

    var stream = vfs.src(expectedPath, { cwd: __dirname, base: __dirname });
    stream.on('data', function(file) {
      files.push(file);
    });
    stream.once('end', function() {
      files.length.should.equal(2);
      files[0].should.eql(expectedFile);
      bufEqual(files[0].contents, expectedContent).should.equal(true);
      files[1].should.eql(expectedFile);
      bufEqual(files[1].contents, expectedContent).should.equal(true);
      done();
    });
    stream.write(expectedFile);
  });
Exemplo n.º 5
0
    var getDirs = function (baseDir, ignore) {
        var inputPaths = [],
            paths = [],
            i, d, isIgnored, subpath,
            stat, possibleDirs, fullPath;

        var inputPath = '';
        while (inputPath !== undefined) {
            fullPath = path.join(baseDir, inputPath);
            stat = fs.lstatSync(fullPath);

            if (stat.isDirectory()) {
                if (fullPath !== baseDir) {
                    paths.push(fullPath);
                }
                possibleDirs = fs.readdirSync(fullPath);
                for (d=0;d<possibleDirs.length;d++) {
                    subpath = path.join(inputPath, possibleDirs[d]);
                    isIgnored = false;
                    for (i=0;i<ignore.length;i++) {
                        if (subpath.indexOf(ignore[i]) === 0) {
                          isIgnored = true;
                          break;
                        }
                    }
                    if (!isIgnored) {
                      inputPaths.push(subpath);
                    }
                }
            }
            inputPath = inputPaths.pop();
        }

        return paths;
    };
Exemplo n.º 6
0
    var onEnd = function() {
      var stats = fs.lstatSync(expectedPath);

      expect(futimesSpy.calls.length).toEqual(1);
      expect(stats.mtime.getTime()).toEqual(expectedMtime.getTime());
      done();
    };
Exemplo n.º 7
0
    function assert() {
      var stats = fs.lstatSync(outputPath);

      expect(futimesSpy.calls.length).toEqual(0);
      expect(stats.atime.getTime()).toBeGreaterThan(earlier);
      expect(stats.mtime.getTime()).toBeGreaterThan(earlier);
    }
Exemplo n.º 8
0
    function assert() {
      var stats = fs.lstatSync(outputPath);

      expect(futimesSpy.calls.length).toEqual(1);
      expect(stats.mtime.getTime()).toEqual(mtime.getTime());
      expect(file.stat.mtime).toEqual(mtime);
    }
Exemplo n.º 9
0
      fs.close(fd, function() {
        var stats = fs.lstatSync(filepath);

        expect(masked(stats.mode)).toEqual(expected);

        done();
      });
Exemplo n.º 10
0
function writeMetadata(opts, dir, json) {
	var fontsDir = path.join(opts.fullPath, dir);
	var fontsMetadata = path.join(fontsDir, "metadata.json");
	if (fs.existsSync(fontsDir) && fs.lstatSync(fontsDir).isDirectory() && !fs.existsSync(fontsMetadata)) {
		fs.writeFileSync(fontsMetadata, json);
	}
}
Exemplo n.º 11
0
  it('calls futimes when provided mtime on the vinyl stat is valid but provided atime is invalid', function(done) {
    if (isWindows) {
      this.skip();
      return;
    }

    // Use the mtime of this file to have proper resolution
    var mtime = fs.lstatSync(__filename).mtime;
    var invalidAtime = new Date(undefined);

    var futimesSpy = expect.spyOn(fs, 'futimes').andCallThrough();

    var file = new File({
      base: inputBase,
      path: inputPath,
      contents: new Buffer(contents),
      stat: {
        atime: invalidAtime,
        mtime: mtime,
      },
    });

    function assert() {
      var stats = fs.lstatSync(outputPath);

      expect(futimesSpy.calls.length).toEqual(1);
      expect(stats.mtime.getTime()).toEqual(mtime.getTime());
    }

    pipe([
      from.obj([file]),
      vfs.dest(outputBase, { cwd: __dirname }),
      concat(assert),
    ], done);
  });
Exemplo n.º 12
0
 helper.forEachSeries(current, function(file, next) {
   var filepath = path.join(dir, file);
   var stat;
   try {
     stat = fs.lstatSync(filepath);
   }
   catch (err) {
     if (err.code === 'ENOENT') return next();
     throw err;
   }
   if ((dirstat.mtime - stat.mtime) <= 0) {
     var relpath = path.relative(self.options.cwd, filepath);
     if (stat.isDirectory()) {
       // If it was a dir, watch the dir and emit that it was added
       platform(filepath, self._trigger.bind(self));
       if (globule.isMatch(self._patterns, relpath, self.options)) {
         self._emitAll('added', filepath);
       }
       self._wasAddedSub(filepath);
     } else if (globule.isMatch(self._patterns, relpath, self.options)) {
       // Otherwise if the file matches, emit added
       platform(filepath, self._trigger.bind(self));
       if (globule.isMatch(self._patterns, relpath, self.options)) {
         self._emitAll('added', filepath);
       }
     }
   }
   next();
 });
Exemplo n.º 13
0
 fse.move(src, dest, err => {
   assert.ifError(err)
   assert(fs.existsSync(dest))
   // console.log(path.normalize(dest))
   assert(fs.lstatSync(dest).isDirectory())
   done()
 })
Exemplo n.º 14
0
    function assert() {
      var stats = fs.lstatSync(outputPath);

      expect(stats.atime.getTime()).toEqual(atime.getTime());
      expect(stats.mtime.getTime()).toEqual(mtime.getTime());
      expect(file.stat.mtime).toEqual(mtime);
      expect(file.stat.atime).toEqual(atime);
    };
Exemplo n.º 15
0
 stats = folders.forEach(function(folder){
     var stats = fs.lstatSync(path + folder);
     if(now - stats.ctime.getTime() > ttl) {
         rmdir(path + folder, function(err) {
             if (err) console.error(err);
         });
     }
 });
Exemplo n.º 16
0
// Mark folders if not marked
function markDir(file) {
  if (file.slice(-1) !== path.sep) {
    if (fs.lstatSync(file).isDirectory()) {
      file += path.sep;
    }
  }
  return file;
}
Exemplo n.º 17
0
    var onEnd = function() {
      var stats = fs.lstatSync(expectedPath);

      expect(stats.atime.getTime()).toEqual(expectedAtime.getTime());
      expect(stats.mtime.getTime()).toEqual(expectedMtime.getTime());
      expect(expectedFile.stat.mtime).toEqual(expectedMtime);
      expect(expectedFile.stat.atime).toEqual(expectedAtime);
      done();
    };
Exemplo n.º 18
0
 it(`should create broken symlink file using src ${srcpath} and dst ${dstpath}`, () => {
   fn(...args)
   const dstDir = path.dirname(dstpath)
   const dstBasename = path.basename(dstpath)
   const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
   const dstDirContents = fs.readdirSync(dstDir)
   assert.strictEqual(isSymlink, true)
   assert(dstDirContents.indexOf(dstBasename) >= 0)
   assert.throws(() => fs.readFileSync(dstpath, 'utf8'), Error)
 })
Exemplo n.º 19
0
 it(`should create broken symlink dir using src ${srcpath} and dst ${dstpath}`, () => {
   fn.apply(null, args)
   const dstDir = path.dirname(dstpath)
   const dstBasename = path.basename(dstpath)
   const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
   const dstDirContents = fs.readdirSync(dstDir)
   assert.equal(isSymlink, true)
   assert(dstDirContents.indexOf(dstBasename) >= 0)
   assert.throws(() => fs.readdirSync(dstpath), Error)
 })
Exemplo n.º 20
0
 var onEnd = function() {
   assert.equal(buffered.length, 1);
   assert.equal(buffered[0], expectedFile);
   assert.equal(buffered[0].cwd, __dirname, 'cwd should have changed');
   assert.equal(buffered[0].base, expectedBase, 'base should have changed');
   assert.equal(buffered[0].path, expectedPath, 'path should have changed');
   assert.equal(fs.readlinkSync(expectedPath), inputPath);
   assert.equal(fs.lstatSync(expectedPath).isDirectory(), false);
   assert.equal(fs.statSync(expectedPath).isDirectory(), true);
   cb();
 };
Exemplo n.º 21
0
File.prototype.getStats = function() {
  if (typeof this.stats === 'undefined') {
    if (!this.exists) {
      throw new File.FileMissingException('Cannot get stats of nonexistent file.');
    }

    this.stats = FS.lstatSync(this.path);
  }

  return this.stats;
};
Exemplo n.º 22
0
 const callback = err => {
   if (err) return done(err)
   const dstDir = path.dirname(dstpath)
   const dstBasename = path.basename(dstpath)
   const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
   const dstDirContents = fs.readdirSync(dstDir)
   assert.equal(isSymlink, true)
   assert(dstDirContents.indexOf(dstBasename) >= 0)
   assert.throws(() => fs.readdirSync(dstpath), Error)
   return done()
 }
function copySync (src, dest, options) {
  if (typeof options === 'function' || options instanceof RegExp) {
    options = {filter: options}
  }

  options = options || {}
  options.recursive = !!options.recursive

  // default to true for now
  options.clobber = 'clobber' in options ? !!options.clobber : true
  // overwrite falls back to clobber
  options.overwrite = 'overwrite' in options ? !!options.overwrite : options.clobber
  options.dereference = 'dereference' in options ? !!options.dereference : false
  options.preserveTimestamps = 'preserveTimestamps' in options ? !!options.preserveTimestamps : false

  options.filter = options.filter || function () { return true }

  // Warn about using preserveTimestamps on 32-bit node:
  if (options.preserveTimestamps && process.arch === 'ia32') {
    console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
    see https://github.com/jprichardson/node-fs-extra/issues/269`)
  }

  const stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src)
  const destFolder = path.dirname(dest)
  const destFolderExists = fs.existsSync(destFolder)
  let performCopy = false

  if (options.filter instanceof RegExp) {
    console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
    performCopy = options.filter.test(src)
  } else if (typeof options.filter === 'function') performCopy = options.filter(src, dest)

  if (stats.isFile() && performCopy) {
    if (!destFolderExists) mkdir.mkdirsSync(destFolder)
    copyFileSync(src, dest, {
      overwrite: options.overwrite,
      errorOnExist: options.errorOnExist,
      preserveTimestamps: options.preserveTimestamps
    })
  } else if (stats.isDirectory() && performCopy) {
    if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
    const contents = fs.readdirSync(src)
    contents.forEach(content => {
      const opts = options
      opts.recursive = true
      copySync(path.join(src, content), path.join(dest, content), opts)
    })
  } else if (options.recursive && stats.isSymbolicLink() && performCopy) {
    const srcPath = fs.readlinkSync(src)
    fs.symlinkSync(srcPath, dest)
  }
}
Exemplo n.º 24
0
          .then(() => {
            const srcContent = fs.readFileSync(srcpath, 'utf8')
            const dstDir = path.dirname(dstpath)
            const dstBasename = path.basename(dstpath)
            const isSymlink = fs.lstatSync(dstpath).isFile()
            const dstContent = fs.readFileSync(dstpath, 'utf8')
            const dstDirContents = fs.readdirSync(dstDir)

            assert.strictEqual(isSymlink, true)
            assert.strictEqual(srcContent, dstContent)
            assert(dstDirContents.indexOf(dstBasename) >= 0)
          })
Exemplo n.º 25
0
 .then(() => {
   const relative = symlinkPathsSync(srcpath, dstpath)
   const srcContent = fs.readFileSync(relative.toCwd, 'utf8')
   const dstDir = path.dirname(dstpath)
   const dstBasename = path.basename(dstpath)
   const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
   const dstContent = fs.readFileSync(dstpath, 'utf8')
   const dstDirContents = fs.readdirSync(dstDir)
   assert.equal(isSymlink, true)
   assert.equal(srcContent, dstContent)
   assert(dstDirContents.indexOf(dstBasename) >= 0)
 })
Exemplo n.º 26
0
 it(`should create link file using src ${srcpath} and dst ${dstpath}`, () => {
   fn(...args)
   const srcContent = fs.readFileSync(srcpath, 'utf8')
   const dstDir = path.dirname(dstpath)
   const dstBasename = path.basename(dstpath)
   const isSymlink = fs.lstatSync(dstpath).isFile()
   const dstContent = fs.readFileSync(dstpath, 'utf8')
   const dstDirContents = fs.readdirSync(dstDir)
   assert.strictEqual(isSymlink, true)
   assert.strictEqual(srcContent, dstContent)
   assert(dstDirContents.indexOf(dstBasename) >= 0)
 })
Exemplo n.º 27
0
// this looks simpler, and is strictly *faster*, but will
// tie up the JavaScript thread and fail on excessively
// deep directory trees.
function rimrafSync (p, options) {
  options = options || {}
  defaults(options)

  assert(p, 'rimraf: missing path')
  assert.equal(typeof p, 'string', 'rimraf: path should be a string')
  assert(options, 'rimraf: missing options')
  assert.equal(typeof options, 'object', 'rimraf: options should be object')

  var results

  if (options.disableGlob || !glob.hasMagic(p)) {
    results = [p]
  } else {
    try {
      fs.lstatSync(p)
      results = [p]
    } catch (er) {
      results = glob.sync(p, options.glob)
    }
  }

  if (!results.length)
    return

  for (var i = 0; i < results.length; i++) {
    var p = results[i]

    try {
      var st = options.lstatSync(p)
    } catch (er) {
      if (er.code === "ENOENT")
        return
    }

    try {
      // sunos lets the root user unlink directories, which is... weird.
      if (st && st.isDirectory())
        rmdirSync(p, options, null)
      else
        options.unlinkSync(p)
    } catch (er) {
      if (er.code === "ENOENT")
        return
      if (er.code === "EPERM")
        return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
      if (er.code !== "EISDIR")
        throw er
      rmdirSync(p, options, er)
    }
  }
}
Exemplo n.º 28
0
  it('should write file atime and mtime using the vinyl stat', function(done) {
    if (isWindows) {
      this.skip();
      return;
    }

    var inputPath = path.join(__dirname, './fixtures/test.coffee');
    var inputBase = path.join(__dirname, './fixtures/');
    var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
    var expectedContents = fs.readFileSync(inputPath);
    var expectedAtime = fs.lstatSync(inputPath).atime;
    var expectedMtime = fs.lstatSync(inputPath).mtime;

    var expectedFile = new File({
      base: inputBase,
      cwd: __dirname,
      path: inputPath,
      contents: expectedContents,
      stat: {
        atime: expectedAtime,
        mtime: expectedMtime,
      },
    });

    var onEnd = function() {
      var stats = fs.lstatSync(expectedPath);

      expect(stats.atime.getTime()).toEqual(expectedAtime.getTime());
      expect(stats.mtime.getTime()).toEqual(expectedMtime.getTime());
      expect(expectedFile.stat.mtime).toEqual(expectedMtime);
      expect(expectedFile.stat.atime).toEqual(expectedAtime);
      done();
    };

    var stream = vfs.dest('./out-fixtures/', { cwd: __dirname });
    stream.on('end', onEnd);
    stream.write(expectedFile);
    stream.end();
  });
Exemplo n.º 29
0
    function assert(files) {
      var stats = fs.statSync(outputDirpath);
      var lstats = fs.lstatSync(outputDirpath);
      var outputLink = fs.readlinkSync(outputDirpath);

      expect(files.length).toEqual(1);
      expect(files).toInclude(file);
      expect(files[0].base).toEqual(outputBase, 'base should have changed');
      expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
      expect(outputLink).toEqual(path.normalize('../fixtures/foo'));
      expect(stats.isDirectory()).toEqual(true);
      expect(lstats.isDirectory()).toEqual(false);
    }
Exemplo n.º 30
0
 it(`should create symlink dir using src ${srcpath} and dst ${dstpath}`, () => {
   fn.apply(null, args)
   const relative = symlinkPathsSync(srcpath, dstpath)
   const srcContents = fs.readdirSync(relative.toCwd)
   const dstDir = path.dirname(dstpath)
   const dstBasename = path.basename(dstpath)
   const isSymlink = fs.lstatSync(dstpath).isSymbolicLink()
   const dstContents = fs.readdirSync(dstpath)
   const dstDirContents = fs.readdirSync(dstDir)
   assert.equal(isSymlink, true)
   assert.deepEqual(srcContents, dstContents)
   assert(dstDirContents.indexOf(dstBasename) >= 0)
 })