Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Windows may throw UNKNOWN error. If dest already exists,
// fs throws error anyway, so no need to guard against it here.
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlinkSync(resolvedSrc, dest)
throw err
}
if (opts.dereference) {
resolvedDest = path.resolve(process.cwd(), resolvedDest)
}
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
}
// prevent copy if src is a subdir of dest since unlinking
// dest in this case would result in removing src contents
// and therefore a broken symlink would be created.
if (fs.statSync(dest).isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
}
return copyLink(resolvedSrc, dest)
}
}
// Windows may throw UNKNOWN error. If dest already exists,
// fs throws error anyway, so no need to guard against it here.
if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlinkSync(resolvedSrc, dest)
throw err
}
if (opts.dereference) {
resolvedDest = path.resolve(process.cwd(), resolvedDest)
}
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
}
// prevent copy if src is a subdir of dest since unlinking
// dest in this case would result in removing src contents
// and therefore a broken symlink would be created.
if (fs.statSync(dest).isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
}
return copyLink(resolvedSrc, dest)
}
}
fs.readdirSync(pathname).forEach(function(first) { // database
var database = pathname + first;
if (fs.statSync(database).isDirectory() === false) {
return;
}
var metadata = '';
var collections = fs.readdirSync(database);
var metadataPath = path.join(database, '.metadata');
if (fs.existsSync(metadataPath) === true) {
metadata = metadataPath + path.sep;
delete collections[collections.indexOf('.metadata')]; // undefined is not a dir
}
collections.forEach(function(second) { // collection
var collection = path.join(database, second);
if (fs.statSync(collection).isDirectory() === false) {
return;
fs.readdirSync(pathname).forEach(function(first) { // database
var database = pathname + first;
if (fs.statSync(database).isDirectory() === false) {
return next(Error('path is not a Directory'));
}
var metadata = '';
var collections = fs.readdirSync(database);
var metadataPath = path.join(database, '.metadata');
if (fs.existsSync(metadataPath) === true) {
metadata = metadataPath + path.sep;
delete collections[collections.indexOf('.metadata')]; // undefined is not a dir
}
collections.forEach(function(second) { // collection
var collection = path.join(database, second);
if (fs.statSync(collection).isDirectory() === false) {
return;
addedNames.forEach(function(filename) {
var filepath = path.join(absDirPath, filename);
if (fs.existsSync(filepath) &&
fs.statSync(filepath).isDirectory())
{
self.add(filepath);
// mighttttttt need a self.updateDirContents() here in case
// we're somehow adding a path that replaces another one...?
}
});
function bailIfExists ( src, flags, mode ) {
let alreadyExists;
try {
fs.statSync( src );
alreadyExists = true;
} catch ( err ) {
if ( err.code !== 'ENOENT' ) {
throw err;
}
}
if ( alreadyExists ) {
// attempt the operation = that way, we get the intended error message
// TODO can't we just do this in the first place?
fs.openSync( src, flags, mode );
}
}
it('should use different modes for files and directories', function(cb) {
var inputBase = path.join(__dirname, './fixtures');
var inputPath = path.join(__dirname, './fixtures/wow/suchempty');
var expectedBase = path.join(__dirname, './actual/wow');
var expectedDirMode = parseInt('755', 8);
var expectedFileMode = parseInt('655', 8);
var firstFile = new File({
base: inputBase,
cwd: __dirname,
path: inputPath,
stat: fs.statSync(inputPath)
});
var onEnd = function() {
realMode(fs.lstatSync(expectedBase).mode).should.equal(expectedDirMode);
realMode(buffered[0].stat.mode).should.equal(expectedFileMode);
cb();
};
var stream = app.symlink('./actual/', {
cwd: __dirname,
mode: expectedFileMode,
dirMode: expectedDirMode
});
var buffered = [];
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);
function isDirectory(path, link) {
var stat,
result = false;
link = (link === false) ? false : true;
try {
stat = fs.lstatSync(path);
if (stat) {
if (stat.isSymbolicLink() && link) {
stat = fs.statSync(path);
}
result = stat.isDirectory();
}
} catch (e) {
result = false;
}
return result;
}
Y.Files.isDirectory = isDirectory;
Y.each(allfiles, function (filename) {
if (!(filename in self.options.excludes)) {
fullpath = path.join(dir, filename);
stats = fs.statSync(fullpath);
if (stats.isDirectory() && !self.options.norecurse) {
self.parsedir(fullpath);
} else {
files.push(filename);
}
}
});
function createFileSync (file) {
let stats
try {
stats = fs.statSync(file)
} catch (e) {}
if (stats && stats.isFile()) return
const dir = path.dirname(file)
if (!fs.existsSync(dir)) {
mkdir.mkdirsSync(dir)
}
fs.writeFileSync(file, '')
}