Skip to content

Commit 117b2a4

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
fix: do not enqueue write operations on conflict
Closes #2051 Signed-off-by: Akos Kitta <[email protected]>
1 parent 278dd4b commit 117b2a4

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

arduino-ide-extension/src/browser/theia/filesystem/file-resource.ts

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ResourceSaveOptions } from '@theia/core/lib/common/resource';
12
import URI from '@theia/core/lib/common/uri';
23
import { injectable } from '@theia/core/shared/inversify';
34
import {
@@ -7,6 +8,7 @@ import {
78
} from '@theia/filesystem/lib/browser/file-resource';
89
import { FileService } from '@theia/filesystem/lib/browser/file-service';
910
import {
11+
ETAG_DISABLED,
1012
FileOperationError,
1113
FileOperationResult,
1214
} from '@theia/filesystem/lib/common/files';
@@ -51,8 +53,16 @@ class WriteQueuedFileResource extends FileResource {
5153
) {
5254
super(uri, fileService, options);
5355
const originalDoWrite = this['doWrite'];
54-
this['doWrite'] = (content, options) =>
55-
this.writeQueue.add(() => originalDoWrite.bind(this)(content, options));
56+
this['doWrite'] = (content, options) => {
57+
if (isETagDisabledResourceSaveOptions(options)) {
58+
// When force overriding without auto-save do not enqueue the modification, it's already enqueued and the conflict is just being resolved.
59+
// https://github.com/arduino/arduino-ide/issues/2051
60+
return originalDoWrite.bind(this)(content, options);
61+
}
62+
return this.writeQueue.add(() =>
63+
originalDoWrite.bind(this)(content, options)
64+
);
65+
};
5666
const originalSaveStream = this['saveStream'];
5767
if (originalSaveStream) {
5868
this['saveStream'] = (content, options) =>
@@ -83,3 +93,24 @@ class WriteQueuedFileResource extends FileResource {
8393
return super.isInSync();
8494
}
8595
}
96+
97+
// Theia incorrectly sets the disabled ETag on the `stat` instead of the `version` so `FileResourceVersion#is` is unusable.
98+
// https://github.com/eclipse-theia/theia/blob/f9063625b861b8433341fcd1a29a0d0298778f4c/packages/filesystem/src/browser/file-resource.ts#L210
99+
// https://github.com/eclipse-theia/theia/blob/f9063625b861b8433341fcd1a29a0d0298778f4c/packages/filesystem/src/browser/file-resource.ts#L34
100+
// https://github.com/eclipse-theia/theia/discussions/12502
101+
function isETagDisabledResourceSaveOptions(
102+
options?: ResourceSaveOptions
103+
): boolean {
104+
if (typeof options === 'object') {
105+
if ('version' in options && typeof options['version'] === 'object') {
106+
const version = <Record<string, unknown>>options['version'];
107+
if (version && 'stat' in version && typeof version['stat'] === 'object') {
108+
const stat = <Record<string, unknown>>version['stat'];
109+
if (stat) {
110+
return 'etag' in stat && stat['etag'] === ETAG_DISABLED;
111+
}
112+
}
113+
}
114+
}
115+
return false;
116+
}

0 commit comments

Comments
 (0)