Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
diff.applyPatches(patchContent, {
loadFile: function(index, callback) {
try {
const fileName = trimUpToFirstSlash(index.oldFileName);
if (patchedFiles[fileName]) {
return callback(null, patchedFiles[fileName]);
}
const filePath = path.resolve(relative, fileName);
const content = fs.readFileSync(filePath, 'utf8');
// create an `.orig` copy of the file prior to patching it
// used in case we need to revert a patch
const origFilePath = filePath + '.orig';
fs.writeFileSync(origFilePath, content);
callback(null, content);
function apply() {
var failed = [], successed = [];
mDiff.applyPatches(file, {
getUnprefixFile: function(f) {
return f.split("/").slice(1).join("/");
},
getFile: function(f) {
return path.join(repo.workdir(), this.getUnprefixFile(f));
},
loadFile: function(index, cb) {
if (!index.oldFileName) {
return cb({message: "Patch is not valid: missing old file name."});
}
if (index.oldFileName === "/dev/null") {
return cb(null, "");
}
fs.readFile(this.getFile(index.oldFileName), "utf8", cb);
},
patched: function(index, content, cb) {