You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Removed requirement for unique folder title
This commit is contained in:
		| @@ -3,12 +3,12 @@ require('babel-plugin-transform-runtime'); | ||||
|  | ||||
| import { time } from 'lib/time-utils.js'; | ||||
| import { Logger } from 'lib/logger.js'; | ||||
| import { dirname } from 'lib/path-utils.js'; | ||||
| import lodash from 'lodash'; | ||||
|  | ||||
| const exec = require('child_process').exec | ||||
| const fs = require('fs-extra'); | ||||
|  | ||||
| const baseDir = '/var/www/joplin/CliClient/tests/fuzzing'; | ||||
| const baseDir = dirname(__dirname) + '/tests/fuzzing'; | ||||
| const syncDir = baseDir + '/sync'; | ||||
| const joplinAppPath = __dirname + '/main.js'; | ||||
| let syncDurations = []; | ||||
| @@ -85,13 +85,21 @@ function execCommand(client, command, options = {}) { | ||||
| 	}); | ||||
| } | ||||
|  | ||||
| async function clientItems(client) { | ||||
| 	let itemsJson = await execCommand(client, 'dump'); | ||||
| 	try { | ||||
| 		return JSON.parse(itemsJson); | ||||
| 	} catch (error) { | ||||
| 		throw new Error('Cannot parse JSON: ' + itemsJson); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| async function execRandomCommand(client) { | ||||
| 	let possibleCommands = [ | ||||
| 		['mkbook {word}', 40], // CREATE FOLDER | ||||
| 		['mknote {word}', 70], // CREATE NOTE | ||||
| 		[async () => { // DELETE RANDOM ITEM | ||||
| 			let items = await execCommand(client, 'dump'); | ||||
| 			items = JSON.parse(items); | ||||
| 			let items = clientItems(client); | ||||
| 			let item = randomElement(items); | ||||
| 			if (!item) return; | ||||
|  | ||||
| @@ -114,8 +122,7 @@ async function execRandomCommand(client) { | ||||
| 			return execCommand(client, 'sync --random-failures', options); | ||||
| 		}, 30], | ||||
| 		[async () => { // UPDATE RANDOM ITEM | ||||
| 			let items = await execCommand(client, 'dump'); | ||||
| 			items = JSON.parse(items); | ||||
| 			let items = clientItems(client); | ||||
| 			let item = randomElement(items); | ||||
| 			if (!item) return; | ||||
|  | ||||
|   | ||||
							
								
								
									
										0
									
								
								CliClient/fuzzing.sh
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								CliClient/fuzzing.sh
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -425,7 +425,7 @@ describe('Synchronizer', function() { | ||||
| 		done(); | ||||
| 	}); | ||||
|  | ||||
| 	it('should allow duplicate folder title and rename the new one', async (done) => { | ||||
| 	it('should allow duplicate folder titles', async (done) => { | ||||
| 		let localF1 = await Folder.save({ title: "folder" }); | ||||
|  | ||||
| 		await switchClient(2); | ||||
| @@ -441,7 +441,7 @@ describe('Synchronizer', function() { | ||||
|  | ||||
| 		let localF2 = await Folder.load(remoteF2.id); | ||||
|  | ||||
| 		expect(localF2.title == remoteF2.title).toBe(false); | ||||
| 		expect(localF2.title == remoteF2.title).toBe(true); | ||||
|  | ||||
| 		// Then that folder that has been renamed locally should be set in such a way | ||||
| 		// that synchronizing it applies the title change remotely, and that new title | ||||
| @@ -460,5 +460,5 @@ describe('Synchronizer', function() { | ||||
|  | ||||
| 		done(); | ||||
| 	}); | ||||
|  | ||||
| 	 | ||||
| }); | ||||
| @@ -18,6 +18,7 @@ let currentClient_ = 1; | ||||
|  | ||||
| const logger = new Logger(); | ||||
| logger.addTarget('file', { path: __dirname + '/data/log-test.txt' }); | ||||
| //logger.addTarget('console'); | ||||
| logger.setLevel(Logger.LEVEL_DEBUG); | ||||
|  | ||||
| function sleep(n) { | ||||
|   | ||||
| @@ -86,20 +86,12 @@ class Folder extends BaseItem { | ||||
| 	} | ||||
|  | ||||
| 	static save(o, options = null) { | ||||
| 		return Folder.loadByField('title', o.title).then((existingFolder) => { | ||||
| 			if (existingFolder && existingFolder.id != o.id) { | ||||
| 				let error = new Error(_('A notebook with title "%s" already exists', o.title)); | ||||
| 				error.code = 'duplicateTitle'; | ||||
| 				throw error; | ||||
| 			} | ||||
|  | ||||
| 			return super.save(o, options).then((folder) => { | ||||
| 				this.dispatch({ | ||||
| 					type: 'FOLDERS_UPDATE_ONE', | ||||
| 					folder: folder, | ||||
| 				}); | ||||
| 				return folder; | ||||
| 		return super.save(o, options).then((folder) => { | ||||
| 			this.dispatch({ | ||||
| 				type: 'FOLDERS_UPDATE_ONE', | ||||
| 				folder: folder, | ||||
| 			}); | ||||
| 			return folder; | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -319,20 +319,7 @@ class Synchronizer { | ||||
| 							await Resource.setContent(newContent, remoteResourceContent); | ||||
| 						} | ||||
|  | ||||
| 						try { | ||||
| 							await ItemClass.save(newContent, options); | ||||
| 						} catch (error) { | ||||
|  | ||||
| 							if (this.randomFailure(options, 3)) return; | ||||
|  | ||||
| 							if (error.code == 'duplicateTitle') { | ||||
| 								newContent.title = newContent.title + '-' + newContent.created_time + '-' + (Math.floor(Math.random() * 1000)); | ||||
| 								newContent.updated_time = newContent.sync_time + 2; | ||||
| 								await ItemClass.save(newContent, options); | ||||
| 							} else { | ||||
| 								throw error; | ||||
| 							} | ||||
| 						} | ||||
| 						await ItemClass.save(newContent, options); | ||||
|  | ||||
| 						if (newContent.type_ == BaseModel.MODEL_TYPE_TAG) { | ||||
| 							let noteIds = newContent.notes_.split(','); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user