Skip to content

Commit bf8a402

Browse files
author
Akos Kitta
committed
fix: do not enqueue write operations on conflict
Closes #2051 Signed-off-by: Akos Kitta <[email protected]>
1 parent 964ea3b commit bf8a402

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

+25
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@theia/filesystem/lib/browser/file-resource';
1010
import { FileService } from '@theia/filesystem/lib/browser/file-service';
1111
import {
12+
ETAG_DISABLED,
1213
FileOperationError,
1314
FileOperationResult,
1415
FileStat,
@@ -66,6 +67,10 @@ class WriteQueuedFileResource extends FileResource {
6667
content: string | Readable<string>,
6768
options?: ResourceSaveOptions
6869
): Promise<void> {
70+
if (isETagDisabledResourceSaveOptions(options)) {
71+
// When force overriding without auto-save do not enqueue the modification. Otherwise, it will never resolve.
72+
return super.doWrite(content, options);
73+
}
6974
return this.writeQueue.add(() => super.doWrite(content, options));
7075
}
7176

@@ -76,3 +81,23 @@ class WriteQueuedFileResource extends FileResource {
7681
return super.isInSync();
7782
}
7883
}
84+
85+
// Theia incorrectly sets the disabled ETag on the `stat` instead of the `version` so `FileResourceVersion#is` is unusable.
86+
// https://github.com/eclipse-theia/theia/blob/f9063625b861b8433341fcd1a29a0d0298778f4c/packages/filesystem/src/browser/file-resource.ts#L210
87+
// https://github.com/eclipse-theia/theia/blob/f9063625b861b8433341fcd1a29a0d0298778f4c/packages/filesystem/src/browser/file-resource.ts#L34
88+
function isETagDisabledResourceSaveOptions(
89+
options?: ResourceSaveOptions
90+
): boolean {
91+
if (typeof options === 'object') {
92+
if ('version' in options && typeof options['version'] === 'object') {
93+
const version = <Record<string, unknown>>options['version'];
94+
if (version && 'stat' in version && typeof version['stat'] === 'object') {
95+
const stat = <Record<string, unknown>>version['stat'];
96+
if (stat) {
97+
return 'etag' in stat && stat['etag'] === ETAG_DISABLED;
98+
}
99+
}
100+
}
101+
}
102+
return false;
103+
}

0 commit comments

Comments
 (0)