Commit f5fefea0 authored by Tristan Cavelier's avatar Tristan Cavelier

Fix bug: get method from conflict manager storage can return conflicts

parent 1a985dad
/*! JIO Storage - v0.1.0 - 2012-08-16 /*! JIO Storage - v0.1.0 - 2012-08-20
* Copyright (c) 2012 Nexedi; Licensed */ * Copyright (c) 2012 Nexedi; Licensed */
(function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, Jio) { (function(LocalOrCookieStorage, $, Base64, sjcl, hex_sha256, Jio) {
...@@ -1793,13 +1793,6 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1793,13 +1793,6 @@ var newConflictManagerStorage = function ( spec, my ) {
doc._creation_date = doc._creation_date =
metadata_file_content[current_revision]._creation_date; metadata_file_content[current_revision]._creation_date;
doc._rev = current_revision; doc._rev = current_revision;
if (command.getOption('revs')) {
doc._revisions = priv._revs(metadata_file_content,
current_revision);
}
if (command.getOption('revs_info')) {
doc._revs_info = priv._revs_info(metadata_file_content);
}
if (metadata_only) { if (metadata_only) {
am.call(o,'success'); am.call(o,'success');
} else { } else {
...@@ -1822,7 +1815,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1822,7 +1815,7 @@ var newConflictManagerStorage = function ( spec, my ) {
); );
}; };
o.checkForConflicts = function () { o.checkForConflicts = function () {
if (metadata_file_content[current_revision].conflict) { if (metadata_file_content[current_revision]._conflict) {
on_conflict = true; on_conflict = true;
conflict_object = conflict_object =
priv.createConflictObject( priv.createConflictObject(
...@@ -1831,25 +1824,39 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -1831,25 +1824,39 @@ var newConflictManagerStorage = function ( spec, my ) {
current_revision current_revision
); );
} }
if (command.getOption('conflicts')) {
doc._conflicts = conflict_object;
}
am.call(o,'success'); am.call(o,'success');
}; };
o.success = function (){ o.success = function (){
am.neverCall(o,'error'); am.neverCall(o,'error');
am.neverCall(o,'success'); am.neverCall(o,'success');
if (command.getOption('revs')) {
doc._revisions = priv._revs(metadata_file_content,
current_revision);
}
if (command.getOption('revs_info')) {
doc._revs_info = priv._revs_info(metadata_file_content);
}
if (command.getOption('conflicts')) {
doc._conflicts = conflict_object;
}
that.success(doc); that.success(doc);
}; };
o.error = function (error){ o.error = function (error) {
var gooderror = error || {status:0,statusText:'Unknown', var err = error || {status:0,statusText:'Unknown',
message:'Unknown error.'}; message:'Unknown error.'};
if (on_conflict) { if (command.getOption('revs')) {
gooderror.conflict_object = conflict_object; err._revisions = priv._revs(metadata_file_content,
current_revision);
}
if (command.getOption('revs_info')) {
err._revs_info = priv._revs_info(metadata_file_content);
}
if (command.getOption('conflicts')) {
err._conflicts = conflict_object;
} }
am.neverCall(o,'error'); am.neverCall(o,'error');
am.neverCall(o,'success'); am.neverCall(o,'success');
that.error(gooderror); that.error(err);
}; };
am.call(o,'getDistantMetadata'); am.call(o,'getDistantMetadata');
}; };
......
This diff is collapsed.
...@@ -569,13 +569,6 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -569,13 +569,6 @@ var newConflictManagerStorage = function ( spec, my ) {
doc._creation_date = doc._creation_date =
metadata_file_content[current_revision]._creation_date; metadata_file_content[current_revision]._creation_date;
doc._rev = current_revision; doc._rev = current_revision;
if (command.getOption('revs')) {
doc._revisions = priv._revs(metadata_file_content,
current_revision);
}
if (command.getOption('revs_info')) {
doc._revs_info = priv._revs_info(metadata_file_content);
}
if (metadata_only) { if (metadata_only) {
am.call(o,'success'); am.call(o,'success');
} else { } else {
...@@ -598,7 +591,7 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -598,7 +591,7 @@ var newConflictManagerStorage = function ( spec, my ) {
); );
}; };
o.checkForConflicts = function () { o.checkForConflicts = function () {
if (metadata_file_content[current_revision].conflict) { if (metadata_file_content[current_revision]._conflict) {
on_conflict = true; on_conflict = true;
conflict_object = conflict_object =
priv.createConflictObject( priv.createConflictObject(
...@@ -607,25 +600,39 @@ var newConflictManagerStorage = function ( spec, my ) { ...@@ -607,25 +600,39 @@ var newConflictManagerStorage = function ( spec, my ) {
current_revision current_revision
); );
} }
if (command.getOption('conflicts')) {
doc._conflicts = conflict_object;
}
am.call(o,'success'); am.call(o,'success');
}; };
o.success = function (){ o.success = function (){
am.neverCall(o,'error'); am.neverCall(o,'error');
am.neverCall(o,'success'); am.neverCall(o,'success');
if (command.getOption('revs')) {
doc._revisions = priv._revs(metadata_file_content,
current_revision);
}
if (command.getOption('revs_info')) {
doc._revs_info = priv._revs_info(metadata_file_content);
}
if (command.getOption('conflicts')) {
doc._conflicts = conflict_object;
}
that.success(doc); that.success(doc);
}; };
o.error = function (error){ o.error = function (error) {
var gooderror = error || {status:0,statusText:'Unknown', var err = error || {status:0,statusText:'Unknown',
message:'Unknown error.'}; message:'Unknown error.'};
if (on_conflict) { if (command.getOption('revs')) {
gooderror.conflict_object = conflict_object; err._revisions = priv._revs(metadata_file_content,
current_revision);
}
if (command.getOption('revs_info')) {
err._revs_info = priv._revs_info(metadata_file_content);
}
if (command.getOption('conflicts')) {
err._conflicts = conflict_object;
} }
am.neverCall(o,'error'); am.neverCall(o,'error');
am.neverCall(o,'success'); am.neverCall(o,'success');
that.error(gooderror); that.error(err);
}; };
am.call(o,'getDistantMetadata'); am.call(o,'getDistantMetadata');
}; };
......
...@@ -1622,6 +1622,7 @@ test ('Revision Conflict', function() { ...@@ -1622,6 +1622,7 @@ test ('Revision Conflict', function() {
o.rev.third = err.rev; o.rev.third = err.rev;
err.rev = checkRev(err.rev); err.rev = checkRev(err.rev);
if (err.conflicts && err.conflicts.rows) { if (err.conflicts && err.conflicts.rows) {
o.tmp = err.conflicts;
o.solveConflict = checkConflictRow (err.conflicts.rows[0]); o.solveConflict = checkConflictRow (err.conflicts.rows[0]);
} }
for (k in {'error':0,'message':0,'reason':0,'statusText':0}) { for (k in {'error':0,'message':0,'reason':0,'statusText':0}) {
...@@ -1654,11 +1655,15 @@ test ('Revision Conflict', function() { ...@@ -1654,11 +1655,15 @@ test ('Revision Conflict', function() {
o.tick(o); o.tick(o);
o.checkContent ('file.doc.'+o.rev.third); o.checkContent ('file.doc.'+o.rev.third);
// loading test // loading test
o.spy(o,'value',{_id:'file.doc',_rev:o.rev.third,content:'content3'}, o.spy(o,'value',{_id:'file.doc',_rev:o.rev.third,content:'content3',
_conflicts:o.tmp},
'loading "file.doc" -> conflict!'); 'loading "file.doc" -> conflict!');
o.jio.get('file.doc',function (err,val) { o.jio.get('file.doc',{conflicts:true},function (err,val) {
var k; var k;
if (val) { if (val) {
if (val._conflicts && val._conflicts.rows) {
checkConflictRow (val._conflicts.rows[0]);
}
for (k in {'_creation_date':0,'_last_modified':0}) { for (k in {'_creation_date':0,'_last_modified':0}) {
if (val[k]) { if (val[k]) {
delete val[k]; delete val[k];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment