1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-27 10:32:58 +02:00

All: Fixes #61: Handle path that ends with slash for file system sync.

This commit is contained in:
Laurent Cozic 2018-05-08 11:29:25 +01:00
parent facf8afa8b
commit cb617e1b14
2 changed files with 11 additions and 1 deletions

View File

@ -6,6 +6,7 @@ const { time } = require('lib/time-utils.js');
const { sprintf } = require('sprintf-js');
const ObjectUtils = require('lib/ObjectUtils');
const { toTitleCase } = require('lib/string-utils.js');
const { rtrimSlashes } = require('lib/path-utils.js');
const { _, supportedLocalesToLanguages, defaultLocale } = require('lib/locale.js');
const { shim } = require('lib/shim');
@ -122,6 +123,8 @@ class Setting extends BaseModel {
} catch (error) {
return false;
}
}, filter: (value) => {
return value ? rtrimSlashes(value) : '';
}, public: true, label: () => _('Directory to synchronise with (absolute path)'), description: (appType) => { return appType !== 'cli' ? null : _('The path to synchronise with when file system synchronisation is enabled. See `sync.target`.'); } },
'sync.5.path': { value: '', type: Setting.TYPE_STRING, show: (settings) => { return settings['sync.target'] == SyncTargetRegistry.nameToId('nextcloud') }, public: true, label: () => _('Nextcloud WebDAV URL') },
@ -204,6 +207,7 @@ class Setting extends BaseModel {
if (!this.keyExists(c.key)) continue;
c.value = this.formatValue(c.key, c.value);
c.value = this.filterValue(c.key, c.value);
this.cache_.push(c);
}
@ -237,6 +241,7 @@ class Setting extends BaseModel {
if (!this.cache_) throw new Error('Settings have not been initialized!');
value = this.formatValue(key, value);
value = this.filterValue(key, value);
for (let i = 0; i < this.cache_.length; i++) {
let c = this.cache_[i];
@ -307,6 +312,11 @@ class Setting extends BaseModel {
throw new Error('Unhandled value type: ' + md.type);
}
static filterValue(key, value) {
const md = this.settingMetadata(key);
return md.filter ? md.filter(value) : value;
}
static formatValue(key, value) {
const md = this.settingMetadata(key);

View File

@ -46,7 +46,7 @@ function toSystemSlashes(path, os) {
}
function rtrimSlashes(path) {
return path.replace(/\/+$/, '');
return path.replace(/[\/\\]+$/, '');
}
function ltrimSlashes(path) {