summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniko <niko>2012-07-04 11:08:45 (GMT)
committerniko <niko>2012-07-04 11:08:45 (GMT)
commitd957ef44ac3327647f3d2793b6cc6222367dcbce (patch)
tree44b0511531021b04b607a22e0b209dde721929ce
parentada6f748c106899b12010101fdf8ab5b8644dee3 (diff)
downloadsynckolab-d957ef44ac3327647f3d2793b6cc6222367dcbce.tar.gz
fix #24967
-rw-r--r--src/chrome/content/synckolab/addressbookTools.js31
-rw-r--r--src/chrome/content/synckolab/tools.js26
2 files changed, 33 insertions, 24 deletions
diff --git a/src/chrome/content/synckolab/addressbookTools.js b/src/chrome/content/synckolab/addressbookTools.js
index 568899b..22cd42a 100644
--- a/src/chrome/content/synckolab/addressbookTools.js
+++ b/src/chrome/content/synckolab/addressbookTools.js
@@ -1432,27 +1432,30 @@ com.synckolab.addressbookTools.equalsContact = function (a, b) {
return false;
}
- if(a.contacts && !b.contacts && a.contacts.length !== 0) {
- com.synckolab.tools.logMessage("different amount of contacts in each list", com.synckolab.global.LOG_DEBUG + com.synckolab.global.LOG_AB);
- return false;
+ // create an array of all contacts of A
+ var aContacts = [];
+ var bContacts = [];
+ if(a.contacts) {
+ for (i = 0; i < a.contacts.length; i++) {
+ aContacts.push(a.contacts[i]);
+ }
}
-
- if(!a.contacts && b.contacts && b.contacts.length !== 0) {
- com.synckolab.tools.logMessage("different amount of contacts in each list", com.synckolab.global.LOG_DEBUG + com.synckolab.global.LOG_AB);
- return false;
+ if(b.contacts) {
+ for (i = 0; i < b.contacts.length; i++) {
+ bContacts.push(b.contacts[i]);
+ }
}
- // create an array of all contacts of A
- var aContacts = [];
- for (i = 0; i < a.contacts.length; i++) {
- aContacts.push(a.contacts[i]);
+ if(aContacts.length !== bContacts.length) {
+ com.synckolab.tools.logMessage("different amount of contacts in each list (a:"+aContacts.length +" b: " + bContacts.length+")", com.synckolab.global.LOG_DEBUG + com.synckolab.global.LOG_AB);
+ return false;
}
// now go through b - if the entry exists in aContacts - remove
- for (i = 0; i < b.contacts.length; i++) {
+ for (i = 0; i < bContacts.length; i++) {
var found = false;
for ( var j = 0; j < aContacts.length; j++) {
- if (aContacts[j].UUID === b.contacts[i].UUID) {
+ if (aContacts[j].UUID === bContacts[i].UUID) {
found = true;
aContacts.splice(j, 1);
break;
@@ -1460,7 +1463,7 @@ com.synckolab.addressbookTools.equalsContact = function (a, b) {
}
// break at the first contact that has not been found
if (!found) {
- com.synckolab.tools.logMessage("contact: " + b.contacts[i].UUID + " not in both lists!", com.synckolab.global.LOG_DEBUG + com.synckolab.global.LOG_AB);
+ com.synckolab.tools.logMessage("contact: " + bContacts[i].UUID + " not in both lists!", com.synckolab.global.LOG_DEBUG + com.synckolab.global.LOG_AB);
return false;
}
}
diff --git a/src/chrome/content/synckolab/tools.js b/src/chrome/content/synckolab/tools.js
index c3652b6..0384ff8 100644
--- a/src/chrome/content/synckolab/tools.js
+++ b/src/chrome/content/synckolab/tools.js
@@ -923,7 +923,12 @@ com.synckolab.tools.writeSyncDBFile = function (file, data, direct)
file.create(file.NORMAL_FILE_TYPE, parseInt("0666", 8));
var stream = Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream);
stream.init(file, 2, 0x200, false); // open as "write only"
- stream.write(skcontent, skcontent.length);
+
+ var cstream = Components.classes["@mozilla.org/intl/converter-output-stream;1"].createInstance(Components.interfaces.nsIConverterOutputStream);
+ cstream.init(stream, "UTF-8", 0, 0);
+
+ cstream.writeString(skcontent);
+ cstream.close();
stream.close();
};
@@ -953,19 +958,20 @@ com.synckolab.tools.readSyncDBFile = function (file, direct)
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
istream.init(file, 0x01, 4, null);
- var fileScriptableIO = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
- fileScriptableIO.init(istream);
- // parse the xml into our internal document
- istream.QueryInterface(Components.interfaces.nsILineInputStream);
+
+ var cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"].createInstance(Components.interfaces.nsIConverterInputStream);
+ cstream.init(istream, "UTF-8", 0, 0);
+
var fileContent = "";
var csize = 0;
- while ((csize = fileScriptableIO.available()) !== 0)
+ var str = {};
+ while (cstream.readString(4096, str) !== 0)
{
- fileContent += fileScriptableIO.read( csize );
+ fileContent += str.value;
}
- fileScriptableIO.close();
- istream.close();
-
+
+ cstream.close();
+
// use json instead
if (direct) {
return fileContent;