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

Desktop: Fixed resource watching on Windows

This commit is contained in:
Laurent Cozic 2020-11-23 16:38:29 +00:00
parent 62c67cb09f
commit c213d5056c

View File

@ -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);