From c213d5056c4bcfe7bb125e4b4b15ad8a7e89c34c Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 23 Nov 2020 16:38:29 +0000 Subject: [PATCH] Desktop: Fixed resource watching on Windows --- .../lib/services/ResourceEditWatcher/index.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/lib/services/ResourceEditWatcher/index.ts b/packages/lib/services/ResourceEditWatcher/index.ts index 0c59817eea..a97fda2fd3 100644 --- a/packages/lib/services/ResourceEditWatcher/index.ts +++ b/packages/lib/services/ResourceEditWatcher/index.ts @@ -1,6 +1,7 @@ import AsyncActionQueue from '../../AsyncActionQueue'; import shim from '../../shim'; import { _ } from '../../locale'; +import { toSystemSlashes } from '../../path-utils'; const Logger = require('../../Logger').default; const Setting = require('../../models/Setting').default; const Resource = require('../../models/Resource'); @@ -157,6 +158,8 @@ export default class ResourceEditWatcher { if (!this.watcher_) { this.watcher_ = this.chokidar_.watch(fileToWatch); this.watcher_.on('all', async (event: any, path: string) => { + path = toSystemSlashes(path, 'linux'); + this.logger().info(`ResourceEditWatcher: Event: ${event}: ${path}`); if (event === 'unlink') { @@ -183,11 +186,13 @@ export default class ResourceEditWatcher { // // @ts-ignore Leave unused path variable this.watcher_.on('raw', async (event: string, path: string, options: any) => { - this.logger().debug(`ResourceEditWatcher: Raw event: ${event}: ${options.watchedPath}`); + const watchedPath = toSystemSlashes(options.watchedPath, 'linux'); + + this.logger().debug(`ResourceEditWatcher: Raw event: ${event}: ${watchedPath}`); if (event === 'rename') { - this.watcher_.unwatch(options.watchedPath); - this.watcher_.add(options.watchedPath); - handleChangeEvent(options.watchedPath); + this.watcher_.unwatch(watchedPath); + this.watcher_.add(watchedPath); + handleChangeEvent(watchedPath); } }); } else { @@ -218,7 +223,7 @@ export default class ResourceEditWatcher { if (!(await Resource.isReady(resource))) throw new Error(_('This attachment is not downloaded or not decrypted yet')); const sourceFilePath = Resource.fullPath(resource); const tempDir = await this.tempDir(); - const editFilePath = await shim.fsDriver().findUniqueFilename(`${tempDir}/${Resource.friendlySafeFilename(resource)}`); + const editFilePath = toSystemSlashes(await shim.fsDriver().findUniqueFilename(`${tempDir}/${Resource.friendlySafeFilename(resource)}`), 'linux'); await shim.fsDriver().copy(sourceFilePath, editFilePath); const stat = await shim.fsDriver().stat(editFilePath);