Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
return fs.renameSync(src, dest)
} catch (err) {
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') {
removeSync(dest)
options.overwrite = false // just overwriteed it, no need to do it again
return moveSync(src, dest, options)
}
if (err.code !== 'EXDEV') throw err
return moveSyncAcrossDevice(src, dest, overwrite)
}
} else {
try {
fs.linkSync(src, dest)
return fs.unlinkSync(src)
} catch (err) {
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
return moveSyncAcrossDevice(src, dest, overwrite)
}
throw err
}
}
}
}
try {
return fs.renameSync(src, dest)
} catch (err) {
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') {
removeSync(dest)
options.overwrite = false // just overwriteed it, no need to do it again
return moveSync(src, dest, options)
}
if (err.code !== 'EXDEV') throw err
return moveSyncAcrossDevice(src, dest, overwrite)
}
} else {
try {
fs.linkSync(src, dest)
return fs.unlinkSync(src)
} catch (err) {
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
return moveSyncAcrossDevice(src, dest, overwrite)
}
throw err
}
}
}
}
function copyLink (resolvedSrc, dest) {
fs.unlinkSync(dest)
return fs.symlinkSync(resolvedSrc, dest)
}
function copyLink (resolvedSrc, dest) {
fs.unlinkSync(dest)
return fs.symlinkSync(resolvedSrc, dest)
}
function rmdirSync(path){
var files = fs.readdirSync(path);
var childPath;
var stats;
for (var i = 0, len = files.length; i < len; i++){
childPath = join(path, files[i]);
stats = fs.statSync(childPath);
if (stats.isDirectory()){
rmdirSync(childPath);
} else {
fs.unlinkSync(childPath);
}
}
fs.rmdirSync(path);
}
function cleanupSync () {
try {
fs.unlinkSync(writeStream.__atomicTmp)
} finally {
return
}
}
}
const fdr = fs.openSync(src, 'r')
const stat = fs.fstatSync(fdr)
const fdw = fs.openSync(dest, flags, stat.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
}
fs.closeSync(fdr)
fs.closeSync(fdw)
return fs.unlinkSync(src)
}
function copyFileSync (srcFile, destFile, options) {
const overwrite = options.overwrite
const errorOnExist = options.errorOnExist
const preserveTimestamps = options.preserveTimestamps
if (fs.existsSync(destFile)) {
if (overwrite) {
fs.unlinkSync(destFile)
} else if (errorOnExist) {
throw new Error(`${destFile} already exists`)
} else return
}
const fdr = fs.openSync(srcFile, 'r')
const stat = fs.fstatSync(fdr)
const fdw = fs.openSync(destFile, 'w', stat.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
}
stream.on('end', function () {
//remove out remporary file
fs.unlinkSync(outImg);
});
}
function deletePath(path) {
var stats = fs.lstatSync(path);
if (stats.isFile() || stats.isSymbolicLink()) {
fs.unlinkSync(path);
} else if (stats.isDirectory()) {
fs.readdirSync(path).forEach(function (filename) {
deletePath(fsPath.join(path, filename));
});
fs.rmdirSync(path);
}
}
Y.Files.deletePath = deletePath;