kopia lustrzana https://github.com/c9/core
update document contents even if postprocess command returns error
needed for standardjs which changes file on disk and return error if there are unfixed issuespull/125/merge
rodzic
91a5badde9
commit
2795ef0379
|
@ -1941,6 +1941,9 @@ function syncDocument(docId, doc, client, forceSync, callback) {
|
||||||
|
|
||||||
function doSyncDocument() {
|
function doSyncDocument() {
|
||||||
Fs.readFile(file, "utf8", function (err, contents) {
|
Fs.readFile(file, "utf8", function (err, contents) {
|
||||||
|
if (typeof doc.contents != "string" && doc.contents)
|
||||||
|
doc.contents = doc.contents.toString(); // because it can be a buffer
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return callback(err);
|
return callback(err);
|
||||||
|
|
||||||
|
@ -2197,14 +2200,14 @@ function handleSaveFile(userIds, client, data) {
|
||||||
doSaveDocument(docId, doc, userId, !data.silent, function (err, result) {
|
doSaveDocument(docId, doc, userId, !data.silent, function (err, result) {
|
||||||
logVerbose("[vfs-collab] Saving took", Date.now() - st, "ms - time is now: " + Date.now() + " file:", docId, !err);
|
logVerbose("[vfs-collab] Saving took", Date.now() - st, "ms - time is now: " + Date.now() + " file:", docId, !err);
|
||||||
if (err) {
|
if (err) {
|
||||||
client.send({
|
client.send({
|
||||||
type: "POST_PROCESSOR_ERROR",
|
type: "POST_PROCESSOR_ERROR",
|
||||||
data: {
|
data: {
|
||||||
code: err.code,
|
code: err.code,
|
||||||
stderr: result && result.stderr,
|
stderr: err.stderr,
|
||||||
docId: docId,
|
docId: docId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2223,40 +2226,27 @@ function handleSaveFile(userIds, client, data) {
|
||||||
|
|
||||||
function execPostProcessor(absPath, docId, doc, fileContents, client, postProcessor, callback) {
|
function execPostProcessor(absPath, docId, doc, fileContents, client, postProcessor, callback) {
|
||||||
localfsAPI.writeToWatchedFile(absPath, function(afterWrite) {
|
localfsAPI.writeToWatchedFile(absPath, function(afterWrite) {
|
||||||
localfsAPI.execFile(
|
localfsAPI.execFile(postProcessor.command, {
|
||||||
postProcessor.command,
|
args: postProcessor.args.map(function(a) { return a.replace(/\$file/g, absPath); }),
|
||||||
{ args: postProcessor.args.map(function(a) { return a.replace(/\$file/g, absPath); }) },
|
cwd: Path.dirname(absPath),
|
||||||
function(err, result) {
|
},
|
||||||
if (err) return done(err);
|
function(err, result) {
|
||||||
|
|
||||||
afterWrite(function() {
|
|
||||||
Fs.readFile(absPath, "utf8", done);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
function done(err, result) {
|
|
||||||
var newFileContents = result && result.toString().replace(/\n/g, doc.newLineChar || DEFAULT_NL_CHAR_FILE);
|
|
||||||
if (!newFileContents || newFileContents === fileContents) {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
client.send({
|
client.send({
|
||||||
type: "POST_PROCESSOR_ERROR",
|
type: "POST_PROCESSOR_ERROR",
|
||||||
data: {
|
data: {
|
||||||
code: err.code,
|
code: err.code,
|
||||||
stderr: result && result.stderr,
|
stderr: err.stderr,
|
||||||
docId: docId,
|
docId: docId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return callback();
|
|
||||||
}
|
}
|
||||||
return callback();
|
|
||||||
}
|
syncDocument(docId, doc, null, true, function() {
|
||||||
|
afterWrite(callback)
|
||||||
doc.contents = fileContents;
|
});
|
||||||
|
});
|
||||||
syncDocument(docId, doc, null, false, callback);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Ładowanie…
Reference in New Issue