Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function hasMillisRes () {
// 550 millis past UNIX epoch
var d = new Date(550)
var tmpfile = path.join(require('os').tmpdir(), 'millis-test')
fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
var fd = fs.openSync(tmpfile, 'r+')
fs.futimesSync(fd, d, d)
fs.closeSync(fd)
return fs.statSync(tmpfile).mtime > 0
}
function findAccessibleSync (logprefix, dir, candidates) {
for (var next = 0; next < candidates.length; next++) {
var candidate = path.resolve(dir, candidates[next])
try {
var fd = fs.openSync(candidate, 'r')
} catch (e) {
// this candidate was not found or not readable, do nothing
log.silly(logprefix, 'Could not open %s: %s', candidate, e.message)
continue
}
fs.closeSync(fd)
log.silly(logprefix, 'Found readable %s', candidate)
return candidate
}
return undefined
}
throw err;
}
}
if ( alreadyExists ) {
// attempt the operation = that way, we get the intended error message
fs.openSync( src, flags, options.mode );
}
}
if ( isSync ) {
if ( shouldCreateDirs ) {
mkdirp.sync( path.dirname( src ) );
}
return fs.openSync( src, flags, options.mode );
}
return new Promise( function ( fulfil, reject ) {
if ( shouldCreateDirs ) {
mkdirp( path.dirname( src ), function ( err, result ) {
if ( err ) {
reject( err );
} else {
open();
}
});
} else {
open();
}
function open () {
function findAccessibleSync (logprefix, dir, candidates) {
for (var next = 0; next < candidates.length; next++) {
var candidate = path.resolve(dir, candidates[next])
try {
var fd = fs.openSync(candidate, 'r')
} catch (e) {
// this candidate was not found or not readable, do nothing
log.silly(logprefix, 'Could not open %s: %s', candidate, e.message)
continue
}
fs.closeSync(fd)
log.silly(logprefix, 'Found readable %s', candidate)
return candidate
}
return undefined
}
function copyFileFallback (srcStat, src, dest, opts) {
const BUF_LENGTH = 64 * 1024
const _buff = require('../util/buffer')(BUF_LENGTH)
const fdr = fs.openSync(src, 'r')
const fdw = fs.openSync(dest, 'w', srcStat.mode)
let pos = 0
while (pos < srcStat.size) {
const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
fs.writeSync(fdw, _buff, 0, bytesRead)
pos += bytesRead
}
if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime)
fs.closeSync(fdr)
fs.closeSync(fdw)
}
function copyFileFallback (srcStat, src, dest, opts) {
const BUF_LENGTH = 64 * 1024
const _buff = require('../util/buffer')(BUF_LENGTH)
const fdr = fs.openSync(src, 'r')
const fdw = fs.openSync(dest, 'w', srcStat.mode)
let pos = 0
while (pos < srcStat.size) {
const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
fs.writeSync(fdw, _buff, 0, bytesRead)
pos += bytesRead
}
if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime)
fs.closeSync(fdr)
fs.closeSync(fdw)
}
var file = new File({
base: inputBase,
path: inputPath,
contents: new Buffer(contents),
stat: {
mode: expectedMode,
},
});
function assert() {
expect(statMode(outputPath)).toEqual(expectedMode);
}
fs.mkdirSync(outputBase);
fs.closeSync(fs.openSync(outputPath, 'w'));
fs.chmodSync(outputPath, startMode);
pipe([
from.obj([file]),
vfs.dest(outputBase, { cwd: __dirname }),
concat(assert),
], done);
});
}
var fchmodSpy = expect.spyOn(fs, 'fchmod').andCallThrough();
var mode = applyUmask('777');
var file = new File({
base: outputBase,
path: outputPath,
contents: null,
stat: {
mode: mode,
},
});
var fd = fs.openSync(outputPath, 'w+');
updateMetadata(fd, file, function() {
expect(fchmodSpy.calls.length).toEqual(1);
var stats = fs.fstatSync(fd);
expect(file.stat.mode).toEqual(stats.mode);
fs.close(fd, done);
});
});
base: inputBase,
cwd: __dirname,
path: inputPath,
contents: expectedContents,
stat: {
mode: expectedMode
}
});
var onEnd = function() {
assert.equal(masked(fs.lstatSync(expectedPath).mode), expectedMode);
cb();
};
fs.mkdirSync(expectedBase);
fs.closeSync(fs.openSync(expectedPath, 'w'));
fs.chmodSync(expectedPath, startMode);
var stream = app.dest('actual/', { cwd: __dirname });
stream.on('end', onEnd);
stream.write(expectedFile);
stream.end();
});
function copyFileFallback (srcStat, src, dest, opts) {
const BUF_LENGTH = 64 * 1024
const _buff = require('../util/buffer')(BUF_LENGTH)
const fdr = fs.openSync(src, 'r')
const fdw = fs.openSync(dest, 'w', srcStat.mode)
let bytesRead = 1
let pos = 0
while (bytesRead > 0) {
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
fs.writeSync(fdw, _buff, 0, bytesRead)
pos += bytesRead
}
if (opts.preserveTimestamps) fs.futimesSync(fdw, srcStat.atime, srcStat.mtime)
fs.closeSync(fdr)
fs.closeSync(fdw)
}