@@ -124,49 +124,12 @@ public void create(InputStream content, int updateFlags, IProgressMonitor monito
124
124
try (content ) {
125
125
checkValidPath (path , FILE , true );
126
126
final ISchedulingRule rule = workspace .getRuleFactory ().createRule (this );
127
- SubMonitor newChild = subMonitor .newChild (1 );
128
127
try {
129
- workspace .prepareOperation (rule , newChild );
130
- checkDoesNotExist ();
131
- Container parent = (Container ) getParent ();
132
- ResourceInfo info = parent .getResourceInfo (false , false );
133
- parent .checkAccessible (getFlags (info ));
134
- checkValidGroupContainer (parent , false , false );
135
-
128
+ workspace .prepareOperation (rule , subMonitor .newChild (1 ));
129
+ checkCreatable ();
136
130
workspace .beginOperation (true );
137
131
IFileStore store = getStore ();
138
- IFileInfo localInfo = store .fetchInfo ();
139
- if (BitMask .isSet (updateFlags , IResource .FORCE )) {
140
- if (!Workspace .caseSensitive ) {
141
- if (localInfo .exists ()) {
142
- String name = getLocalManager ().getLocalName (store );
143
- if (name == null || localInfo .getName ().equals (name )) {
144
- delete (true , null );
145
- } else {
146
- // The file system is not case sensitive and there is already a file
147
- // under this location.
148
- message = NLS .bind (Messages .resources_existsLocalDifferentCase , IPath .fromOSString (store .toString ()).removeLastSegments (1 ).append (name ).toOSString ());
149
- throw new ResourceException (IResourceStatus .CASE_VARIANT_EXISTS , getFullPath (), message , null );
150
- }
151
- }
152
- }
153
- } else {
154
- if (localInfo .exists ()) {
155
- //return an appropriate error message for case variant collisions
156
- if (!Workspace .caseSensitive ) {
157
- String name = getLocalManager ().getLocalName (store );
158
- if (name != null && !localInfo .getName ().equals (name )) {
159
- message = NLS .bind (Messages .resources_existsLocalDifferentCase , IPath .fromOSString (store .toString ()).removeLastSegments (1 ).append (name ).toOSString ());
160
- throw new ResourceException (IResourceStatus .CASE_VARIANT_EXISTS , getFullPath (), message , null );
161
- }
162
- }
163
- message = NLS .bind (Messages .resources_fileExists , store .toString ());
164
- throw new ResourceException (IResourceStatus .FAILED_WRITE_LOCAL , getFullPath (), message , null );
165
- }
166
- }
167
- subMonitor .worked (40 );
168
-
169
- info = workspace .createResource (this , updateFlags );
132
+ IFileInfo localInfo = create (updateFlags , subMonitor .newChild (40 ), store );
170
133
boolean local = content != null ;
171
134
if (local ) {
172
135
try {
@@ -181,9 +144,7 @@ public void create(InputStream content, int updateFlags, IProgressMonitor monito
181
144
throw e ;
182
145
}
183
146
}
184
- internalSetLocal (local , DEPTH_ZERO );
185
- if (!local )
186
- getResourceInfo (true , true ).clearModificationStamp ();
147
+ setLocal (local );
187
148
} catch (OperationCanceledException e ) {
188
149
workspace .getWorkManager ().operationCanceled ();
189
150
throw e ;
@@ -203,6 +164,98 @@ public void create(InputStream content, boolean force, IProgressMonitor monitor)
203
164
create (content , (force ? IResource .FORCE : IResource .NONE ), monitor );
204
165
}
205
166
167
+ @ Override
168
+ public void create (byte [] content , int updateFlags , IProgressMonitor monitor ) throws CoreException {
169
+ SubMonitor subMonitor = SubMonitor .convert (monitor , NLS .bind (Messages .resources_creating , getFullPath ()), 100 );
170
+ try {
171
+ checkValidPath (path , FILE , true );
172
+ final ISchedulingRule rule = workspace .getRuleFactory ().createRule (this );
173
+ try {
174
+ workspace .prepareOperation (rule , subMonitor .newChild (1 ));
175
+ checkCreatable ();
176
+ workspace .beginOperation (true );
177
+ IFileStore store = getStore ();
178
+ IFileInfo localInfo = create (updateFlags , subMonitor .newChild (40 ), store );
179
+ boolean local = content != null ;
180
+ if (local ) {
181
+ try {
182
+ internalSetContents (content , localInfo , updateFlags , false , subMonitor .newChild (59 ));
183
+ } catch (CoreException | OperationCanceledException e ) {
184
+ // CoreException when a problem happened creating the file on disk
185
+ // OperationCanceledException when the operation of setting contents has been
186
+ // canceled
187
+ // In either case delete from the workspace and disk
188
+ workspace .deleteResource (this );
189
+ store .delete (EFS .NONE , null );
190
+ throw e ;
191
+ }
192
+ }
193
+ setLocal (local );
194
+ } catch (OperationCanceledException e ) {
195
+ workspace .getWorkManager ().operationCanceled ();
196
+ throw e ;
197
+ } finally {
198
+ workspace .endOperation (rule , true );
199
+ }
200
+ } finally {
201
+ subMonitor .done ();
202
+ }
203
+ }
204
+
205
+ private void checkCreatable () throws CoreException {
206
+ checkDoesNotExist ();
207
+ Container parent = (Container ) getParent ();
208
+ ResourceInfo info = parent .getResourceInfo (false , false );
209
+ parent .checkAccessible (getFlags (info ));
210
+ checkValidGroupContainer (parent , false , false );
211
+ }
212
+
213
+ private IFileInfo create (int updateFlags , SubMonitor subMonitor , IFileStore store )
214
+ throws CoreException , ResourceException {
215
+ String message ;
216
+ IFileInfo localInfo = store .fetchInfo ();
217
+ if (BitMask .isSet (updateFlags , IResource .FORCE )) {
218
+ if (!Workspace .caseSensitive ) {
219
+ if (localInfo .exists ()) {
220
+ String name = getLocalManager ().getLocalName (store );
221
+ if (name == null || localInfo .getName ().equals (name )) {
222
+ delete (true , null );
223
+ } else {
224
+ // The file system is not case sensitive and there is already a file
225
+ // under this location.
226
+ message = NLS .bind (Messages .resources_existsLocalDifferentCase ,
227
+ IPath .fromOSString (store .toString ()).removeLastSegments (1 ).append (name ).toOSString ());
228
+ throw new ResourceException (IResourceStatus .CASE_VARIANT_EXISTS , getFullPath (), message , null );
229
+ }
230
+ }
231
+ }
232
+ } else {
233
+ if (localInfo .exists ()) {
234
+ // return an appropriate error message for case variant collisions
235
+ if (!Workspace .caseSensitive ) {
236
+ String name = getLocalManager ().getLocalName (store );
237
+ if (name != null && !localInfo .getName ().equals (name )) {
238
+ message = NLS .bind (Messages .resources_existsLocalDifferentCase ,
239
+ IPath .fromOSString (store .toString ()).removeLastSegments (1 ).append (name ).toOSString ());
240
+ throw new ResourceException (IResourceStatus .CASE_VARIANT_EXISTS , getFullPath (), message , null );
241
+ }
242
+ }
243
+ message = NLS .bind (Messages .resources_fileExists , store .toString ());
244
+ throw new ResourceException (IResourceStatus .FAILED_WRITE_LOCAL , getFullPath (), message , null );
245
+ }
246
+ }
247
+ subMonitor .done ();
248
+
249
+ workspace .createResource (this , updateFlags );
250
+ return localInfo ;
251
+ }
252
+
253
+ private void setLocal (boolean local ) throws CoreException {
254
+ internalSetLocal (local , DEPTH_ZERO );
255
+ if (!local )
256
+ getResourceInfo (true , true ).clearModificationStamp ();
257
+ }
258
+
206
259
@ Override
207
260
public String getCharset () throws CoreException {
208
261
return getCharset (true );
0 commit comments