diff --git a/ReactNativeClient/lib/file-api-driver-local.js b/ReactNativeClient/lib/file-api-driver-local.js index 2ffc22f724..1971a003cc 100644 --- a/ReactNativeClient/lib/file-api-driver-local.js +++ b/ReactNativeClient/lib/file-api-driver-local.js @@ -146,11 +146,17 @@ class FileApiDriverLocal { let output = null; try { - if (options.encoding == 'binary') { - output = fs.readFile(path); + if (options.target === 'file') { + output = await fs.copy(path, options.path, { overwrite: true }); } else { - output = fs.readFile(path, options.encoding); + output = await fs.readFile(path, options.encoding); } + + // if (options.encoding == 'binary') { + // output = await fs.readFile(path); + // } else { + // output = await fs.readFile(path, options.encoding); + // } } catch (error) { if (error.code == 'ENOENT') return null; throw this.fsErrorToJsError_(error); diff --git a/ReactNativeClient/lib/joplin-database.js b/ReactNativeClient/lib/joplin-database.js index 574a95ca57..b1826cf09c 100644 --- a/ReactNativeClient/lib/joplin-database.js +++ b/ReactNativeClient/lib/joplin-database.js @@ -290,6 +290,8 @@ class JoplinDatabase extends Database { queries.push('ALTER TABLE ' + n + ' ADD COLUMN encryption_applied INT NOT NULL DEFAULT 0'); queries.push('CREATE INDEX ' + n + '_encryption_applied ON ' + n + ' (encryption_applied)'); } + + queries.push('ALTER TABLE sync_items ADD COLUMN force_sync INT NOT NULL DEFAULT 0'); } queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] }); diff --git a/ReactNativeClient/lib/models/BaseItem.js b/ReactNativeClient/lib/models/BaseItem.js index 2720b228dd..404f9afee6 100644 --- a/ReactNativeClient/lib/models/BaseItem.js +++ b/ReactNativeClient/lib/models/BaseItem.js @@ -424,7 +424,7 @@ class BaseItem extends BaseModel { SELECT %s FROM %s items JOIN sync_items s ON s.item_id = items.id WHERE sync_target = %d - AND s.sync_time < items.updated_time + AND (s.sync_time < items.updated_time OR force_sync = 1) AND s.sync_disabled = 0 %s LIMIT %d @@ -546,6 +546,28 @@ class BaseItem extends BaseModel { return !!item.encryption_applied ? '🔑 ' + _('Encrypted') : item.title + ''; } + static async markAllNonEncryptedForSync() { + const classNames = this.encryptableItemClassNames(); + + for (let i = 0; i < classNames.length; i++) { + const className = classNames[i]; + const ItemClass = this.getClass(className); + + const sql = sprintf(` + SELECT id + FROM %s + WHERE encryption_applied = 0`, + this.db().escapeField(ItemClass.tableName()), + ); + + const items = await ItemClass.modelSelectAll(sql); + const ids = items.map((item) => {return item.id}); + if (!ids.length) continue; + + await this.db().exec('UPDATE sync_items SET force_sync = 1 WHERE item_id IN ("' + ids.join('","') + '")'); + } + } + static async save(o, options = null) { if (!options) options = {}; diff --git a/ReactNativeClient/lib/services/EncryptionService.js b/ReactNativeClient/lib/services/EncryptionService.js index a03d40a2d1..9e4078aa8c 100644 --- a/ReactNativeClient/lib/services/EncryptionService.js +++ b/ReactNativeClient/lib/services/EncryptionService.js @@ -2,6 +2,7 @@ const { padLeft } = require('lib/string-utils.js'); const { shim } = require('lib/shim.js'); const Setting = require('lib/models/Setting.js'); const MasterKey = require('lib/models/MasterKey'); +const BaseItem = require('lib/models/BaseItem'); function hexPad(s, length) { return padLeft(s, length, '0'); @@ -41,6 +42,8 @@ class EncryptionService { passwordCache[masterKey.id] = password; Setting.setValue('encryption.passwordCache', passwordCache); } + + await BaseItem.markAllNonEncryptedForSync(); } async loadMasterKeysFromSettings() {