sync bugfix

This commit is contained in:
Antelle 2015-12-13 17:59:41 +03:00
parent fad40bcea5
commit de92da4daf
7 changed files with 16 additions and 22 deletions

View File

@ -19,7 +19,7 @@ var FileCollection = Backbone.Collection.extend({
},
getByName: function(name) {
return this.find(function(file) { return file.get('name') === name; });
return this.find(function(file) { return file.get('name').toLowerCase() === name.toLowerCase(); });
},
getById: function(id) {

View File

@ -33,8 +33,8 @@ var FileInfoCollection = Backbone.Collection.extend({
});
},
getByName: function() {
return this.find(function(file) { return file.get('name') === name; });
getByName: function(name) {
return this.find(function(file) { return file.get('name').toLowerCase() === name.toLowerCase(); });
}
});

View File

@ -265,7 +265,7 @@ var AppModel = Backbone.Model.extend({
// no storage: load from cache as main storage
logger.info('Open file from cache as main storage');
this.openFileFromCache(params, callback, fileInfo);
} else if (fileInfo && fileInfo.get('rev') === params.rev) {
} else if (fileInfo && fileInfo.get('rev') === params.rev && fileInfo.get('storage') !== 'file') {
// already latest in cache: use it
logger.info('Open file from cache because it is latest');
this.openFileFromCache(params, callback, fileInfo);
@ -355,28 +355,21 @@ var AppModel = Backbone.Model.extend({
file.set('syncDate', fileInfo.get('syncDate'));
}
var cacheId = fileInfo && fileInfo.id || IdGenerator.uuid();
file.set('cacheId', cacheId);
if (updateCacheOnSuccess && params.storage !== 'file') {
logger.info('Save loaded file to cache');
Storage.cache.save(cacheId, params.fileData, function(err) {
if (err && !params.storage) {
return;
}
that.addToLastOpenFiles(file, cacheId, params.rev);
});
Storage.cache.save(cacheId, params.fileData);
}
if (params.storage === 'file') {
that.addToLastOpenFiles(file, cacheId, params.rev);
}
file.set('cacheId', cacheId);
that.addToLastOpenFiles(file, params.rev);
that.addFile(file);
});
},
addToLastOpenFiles: function(file, id, rev) {
this.appLogger.debug('Add last open file', id, file.get('name'), file.get('storage'), file.get('path'));
addToLastOpenFiles: function(file, rev) {
this.appLogger.debug('Add last open file', file.get('cacheId'), file.get('name'), file.get('storage'), file.get('path'));
var dt = new Date();
var fileInfo = new FileInfoModel({
id: id,
id: file.get('cacheId'),
name: file.get('name'),
storage: file.get('storage'),
path: file.get('path'),
@ -386,7 +379,7 @@ var AppModel = Backbone.Model.extend({
syncDate: file.get('syncDate') || dt,
openDate: dt
});
this.fileInfos.remove(id);
this.fileInfos.remove(file.get('cacheId'));
this.fileInfos.unshift(fileInfo);
this.fileInfos.save();
},
@ -548,7 +541,7 @@ var AppModel = Backbone.Model.extend({
logger.info('Saved to cache');
loadFromStorageAndMerge();
} else if (storage === 'file') {
if (file.get('modified')) {
if (file.get('modified') || file.get('path') !== path) {
logger.info('Save modified file to storage');
saveToCacheAndStorage();
} else {

View File

@ -28,7 +28,7 @@ var EntryModel = Backbone.Model.extend({
_fillByEntry: function() {
var entry = this.entry;
this.set({id: entry.uuid.id}, {silent: true});
this.fileName = this.file.db.meta.name;
this.fileName = this.file.get('name');
this.title = entry.fields.Title || '';
this.password = entry.fields.Password || kdbxweb.ProtectedValue.fromString('');
this.notes = entry.fields.Notes || '';

View File

@ -347,6 +347,7 @@ var FileModel = Backbone.Model.extend({
this.set('name', name);
this.get('groups').first().setName(name);
this.setModified();
this.reload();
},
setDefaultUser: function(defaultUser) {

View File

@ -26,6 +26,7 @@ var StorageFileCache = {
fs.mkdirSync(path);
}
this.path = path;
callback();
} catch (e) {
logger.error('Error opening local offline storage', e);
if (callback) { callback(e); }

View File

@ -37,7 +37,7 @@ var SettingsAboutView = Backbone.View.extend({
appModel: null,
initialize: function() {
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'change:syncing change:syncError change:syncDate', this.render);
},
render: function() {
@ -96,7 +96,6 @@ var SettingsAboutView = Backbone.View.extend({
header: 'Empty password',
body: 'Saving database with empty password makes it completely unprotected. Do you really want to do it?',
success: function() {
that.model.setPassword(kdbxweb.ProtectedValue.fromString(''));
continueCallback();
},
cancel: function() {