1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-06 22:17:10 +02:00

Clipper: Fixes #2267: Fixed race condition when importing page that have multiple images with similar names

This commit is contained in:
Laurent Cozic
2020-01-08 18:21:13 +00:00
parent bc7099d29b
commit bf25364333

View File

@@ -23,6 +23,7 @@ const SearchEngineUtils = require('lib/services/SearchEngineUtils');
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
const uri2path = require('file-uri-to-path');
const { MarkupToHtml } = require('joplin-renderer');
const { uuid } = require('lib/uuid');
class ApiError extends Error {
constructor(message, httpCode = 400) {
@@ -586,8 +587,10 @@ class Api {
let fileExt = isDataUrl ? mimeUtils.toFileExtension(mimeUtils.fromDataUrl(url)) : safeFileExtension(fileExtension(url).toLowerCase());
if (!mimeUtils.fromFileExtension(fileExt)) fileExt = ''; // If the file extension is unknown - clear it.
if (fileExt) fileExt = `.${fileExt}`;
let imagePath = `${tempDir}/${safeFilename(name)}${fileExt}`;
if (await shim.fsDriver().exists(imagePath)) imagePath = `${tempDir}/${safeFilename(name)}_${md5(`${Math.random()}_${Date.now()}`).substr(0, 10)}${fileExt}`;
// Append a UUID because simply checking if the file exists is not enough since
// multiple resources can be downloaded at the same time (race condition).
let imagePath = `${tempDir}/${safeFilename(name)}_${uuid.create()}${fileExt}`;
try {
if (isDataUrl) {