9
9
} from '@theia/filesystem/lib/browser/file-resource' ;
10
10
import { FileService } from '@theia/filesystem/lib/browser/file-service' ;
11
11
import {
12
+ ETAG_DISABLED ,
12
13
FileOperationError ,
13
14
FileOperationResult ,
14
15
FileStat ,
@@ -66,6 +67,10 @@ class WriteQueuedFileResource extends FileResource {
66
67
content : string | Readable < string > ,
67
68
options ?: ResourceSaveOptions
68
69
) : 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
+ }
69
74
return this . writeQueue . add ( ( ) => super . doWrite ( content , options ) ) ;
70
75
}
71
76
@@ -76,3 +81,23 @@ class WriteQueuedFileResource extends FileResource {
76
81
return super . isInSync ( ) ;
77
82
}
78
83
}
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