Ejemplo n.º 1
0
before(function() {
	clearUp();
	fs.mkdirsSync(subdir);
	fs.writeFileSync(srcdir + firstTestFile, 'Test Data');
	fs.utimesSync(srcdir + firstTestFile, atime, mtime);
	fs.writeFileSync(srcdir + secondTestFile, 'Test Data');
	fs.utimesSync(srcdir + secondTestFile, atime, mtime);
});
Ejemplo n.º 2
0
 files.forEach(file => {
   fs.utimesSync(
     `${basePath}/${uploadDir}/${file}`,
     Date.now() / 1000,
     (Date.now() - 61 * 60 * 1000) / 1000
   );
 });
Ejemplo n.º 3
0
function process(path, callback) {
  if (exceptions.hasOwnProperty(path)) {
    if (!exceptions[path]) return;
  }
  if (fs.lstatSync(path).isDirectory()) {
    var list = fs.readdirSync(path);
    for (var i = 0; i < list.length; ++i) {
      process(path + "/" + list[i], callback);
    }
  } else {
    var outPath = outDir + "/" + path;
    if (exceptions.hasOwnProperty(path)) {
      if (!exceptions[path]) return;
      outPath = outDir + "/" + exceptions[path];
    }
    var ext = ps.extname(path).substring(1);
    if (extensions[callback].indexOf(ext) >= 0) {
      if (ext != extensions[callback][0]) {
        outPath = outPath.replace(ext, extensions[callback][0]);
      }
      console.log("Processing " + path);
      var res = callbacks[callback](path);
      if (customStep.hasOwnProperty(path) && typeof customStep[path] === "function") {
        res = customStep[path](res);
      }
      writeFile(outPath, res);
    } else {
      fs.createFileSync(outPath);
      fs.copySync(path, outPath);
    }
    var stat = fs.statSync(path);
    fs.utimesSync(outPath, stat.atime, stat.mtime);
  }
}
Ejemplo n.º 4
0
exports.touch = function (file) {
	if (fs.existsSync(file)) {
		fs.utimesSync(file, new Date(), new Date());
	} else {
		fs.writeFileSync(file, '');
	}
};
                            stream.on('finish', function() {
                                if(downloadSuccess){
                                    fs.ensureFileSync(localPath);

                                    //copy temp file to our destination
                                    fs.copySync(stream.path, localPath);

                                    //Write the remote timestamp to our local file
                                    fs.utimesSync(localPath, remoteLastModified, remoteLastModified);

                                    var stat = fs.statSync(localPath);
                                    if(stat.size == 0){
                                        grunt.verbose.writeln('Wrote 0 byte file ', localPath);

                                        stat = fs.statSync(stream.path);
                                        grunt.verbose.writeln('Tmp file was '+stat.size+' bytes.');
                                    }

                                    grunt.verbose.writeln('Removing temp file ', stream.path);
                                    fs.removeSync(stream.path);

                                    grunt.log.ok(localPath);
                                    completeTask(true);
                                }else{
                                    fs.removeSync(stream.path);

                                    if(fileExists && statusCode == 304){
                                        grunt.verbose.writeln('Skipped not modified ', localPath);
                                        completeTask(true);
                                    }else{
                                        grunt.log.error("s3.getObject() "+element.Key, statusCode);
                                        completeTask(false);
                                    }
                                }
                            });
Ejemplo n.º 6
0
/**
 * Set file attributes
 * @function $file~setAttrs
 * @param {string} file
 * @param {Object} [options] - Object containing the file attributes: mode, atime, mtime
 * @param {Date|string|number} [options.atime] - File access time
 * @param {Date|string|number} [options.mtime] - File modification time
 * @param {string} [options.mode] - File permissions
 * @example
 * // Update modification time and permissions of a file
 * $file.setAttrs('timestamp', {mtime: new Date(), mode: '664'});
 */
function setAttrs(file, attrs) {
  if (isLink(file)) return;
  if (_.every([attrs.atime, attrs.mtime], _.identity)) {
    fs.utimesSync(file, new Date(attrs.atime), new Date(attrs.mtime));
  }
  if (attrs.mode) {
    chmod(file, attrs.mode);
  }
}
Ejemplo n.º 7
0
  it('# 清理上传文件:清理部分文件', function (done) {
    var files = fsReadDir(uploadDir);

    for (var i = 0; i < 2; i++) {
      fs.utimesSync(
        `${basePath}/${uploadDir}/${files[i]}`,
        Date.now() / 1000,
        (Date.now() - 61 * 60 * 1000) / 1000
      );
    }

    uploader.clean()
      .then(() => {
        fsReadDir(uploadDir).length.should.equal(4);
        done();
      });
  });
Ejemplo n.º 8
0
 function copytime(file, destFile) {
   var stat = fs.statSync(file);
   fs.chmodSync(destFile, stat.mode);
   fs.utimesSync(destFile, stat.atime, stat.mtime);
 };
Ejemplo n.º 9
0
      // If -a, keep mod time to current.
      let mtime = (options.a === true) ? new Date(stat.mtime) : dateToSet;

      if (options.reference !== undefined) {
        let reference;
        try {
          reference = fs.statSync(options.reference);
        } catch (e) {
          throw new Error(`touch: failed to get attributes of ${options.reference}: No such file or directory`);
        }
        atime = (options.m === true) ? atime : reference.atime;
        mtime = (options.a === true) ? mtime : reference.mtime;
      }

      fs.utimesSync(path, atime, mtime);
      fs.utimesSync(path, atime, mtime);
    } catch (e) {
      throw new Error(e);
    }
  }
};

module.exports = function (vorpal) {
  if (vorpal === undefined) {
    return touch;
  }
  vorpal.api.touch = touch;
  vorpal
    .command('touch <files...>')
    .option('-a', 'change only the access time')