View | Details | Raw Unified | Return to bug 249544 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rse/files/ui/resources/SystemUniversalTempFileListener.java (-65 / +27 lines)
Lines 191-196 Link Here
191
								remoteFile, false, new NullProgressMonitor());
191
								remoteFile, false, new NullProgressMonitor());
192
					}	
192
					}	
193
					
193
					
194
					boolean openEditorAfterUpload = false;
195
					
194
					// get associated editable
196
					// get associated editable
195
					SystemEditableRemoteFile editable = getEditedFile(remoteFile);
197
					SystemEditableRemoteFile editable = getEditedFile(remoteFile);
196
					if (editable != null && storedModifiedStamp == 0)
198
					if (editable != null && storedModifiedStamp == 0)
Lines 209-215 Link Here
209
						{
211
						{
210
							editable = new SystemEditableRemoteFile(remoteFile);
212
							editable = new SystemEditableRemoteFile(remoteFile);
211
						}
213
						}
214
						
215
						openEditorAfterUpload = true;
216
						editable.setLocalResourceProperties();
217
					}
212
218
219
					upload(fs, remoteFile, tempFile, properties, storedModifiedStamp, editable, monitor);	
220
					
221
					if (openEditorAfterUpload){ 
222
						// moving this to after the upload because otherwise it queries the remote file and that messes up the timestamps needed by upload						
213
						final SystemEditableRemoteFile fEditable = editable;
223
						final SystemEditableRemoteFile fEditable = editable;
214
						Display.getDefault().asyncExec(new Runnable() {
224
						Display.getDefault().asyncExec(new Runnable() {
215
							public void run() {
225
							public void run() {
Lines 223-229 Link Here
223
									if (fEditable.checkOpenInEditor() != ISystemEditableRemoteObject.NOT_OPEN)
233
									if (fEditable.checkOpenInEditor() != ISystemEditableRemoteObject.NOT_OPEN)
224
									{
234
									{
225
										try {
235
										try {
226
											fEditable.openEditor();
236
											fEditable.openEditor(); // open e
227
										}
237
										}
228
										catch (PartInitException e) {
238
										catch (PartInitException e) {
229
										}
239
										}
Lines 232-241 Link Here
232
									fEditable.addAsListener();
242
									fEditable.addAsListener();
233
								} 				
243
								} 				
234
						});
244
						});
235
						editable.setLocalResourceProperties();
236
					}
245
					}
237
238
					upload(fs, remoteFile, tempFile, properties, storedModifiedStamp, editable, monitor);				
239
				}
246
				}
240
			} 
247
			} 
241
			catch (SystemMessageException e) {
248
			catch (SystemMessageException e) {
Lines 255-262 Link Here
255
	{
262
	{
256
		try
263
		try
257
		{
264
		{
265
			// make sure the remote file is the current cached version			
266
			remoteFile = fs.getRemoteFileObject(remoteFile.getAbsolutePath(), monitor);
267
			
258
			// get the remote modified timestamp
268
			// get the remote modified timestamp
259
			long remoteModifiedStamp = remoteFile.getLastModified();
269
			long remoteModifiedStamp = remoteFile.getLastModified();
270
			
260
271
261
			boolean remoteFileDeleted = !remoteFile.exists();
272
			boolean remoteFileDeleted = !remoteFile.exists();
262
			// compare timestamps
273
			// compare timestamps
Lines 276-282 Link Here
276
				}
287
				}
277
288
278
				catch (RemoteFileSecurityException e)
289
				catch (RemoteFileSecurityException e)
279
				{
290
				{				
280
					DisplaySystemMessageAction msgAction = new DisplaySystemMessageAction(e.getSystemMessage());
291
					DisplaySystemMessageAction msgAction = new DisplaySystemMessageAction(e.getSystemMessage());
281
					Display.getDefault().syncExec(msgAction);
292
					Display.getDefault().syncExec(msgAction);
282
				}
293
				}
Lines 292-319 Link Here
292
					Display.getDefault().syncExec(msgAction);
303
					Display.getDefault().syncExec(msgAction);
293
				}
304
				}
294
305
306
				// requery the file so get the new timestamp
307
				remoteFile.markStale(true);
308
				remoteFile =fs.getRemoteFileObject(remoteFile.getAbsolutePath(), monitor);
295
				
309
				
296
				IRemoteFile parent = remoteFile.getParentRemoteFile();
310
				IRemoteFile parent = remoteFile.getParentRemoteFile();
297
	
311
312
313
				long ts = remoteFile.getLastModified();
314
				
315
				// set the stored timestamp to be the same as the remote timestamp
316
				properties.setRemoteFileTimeStamp(ts);
317
298
				ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
318
				ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
299
				// refresh
319
				// refresh
300
				if (parent != null)
320
				if (parent != null)
301
				{
321
				{
302
					registry.fireEvent(new SystemResourceChangeEvent(parent, ISystemResourceChangeEvents.EVENT_REFRESH, null));
322
					registry.fireEvent(new SystemResourceChangeEvent(parent, ISystemResourceChangeEvents.EVENT_REFRESH, null));
303
				}
323
				}
304
324
			
305
				// waiting to make sure the file's timestamp is uptodate
306
				remoteFile = waitForTimestampToBeUpToDate(remoteFile,remoteModifiedStamp, monitor);
307
				
308
				
309
							
310
				registry.fireEvent(new SystemResourceChangeEvent(remoteFile, ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE, remoteFile));
325
				registry.fireEvent(new SystemResourceChangeEvent(remoteFile, ISystemResourceChangeEvents.EVENT_PROPERTY_CHANGE, remoteFile));
311
			
326
			
312
				long ts = remoteFile.getLastModified();
313
				
327
				
314
				// set the stored timestamp to be the same as the remote timestamp
315
				properties.setRemoteFileTimeStamp(ts);
316
317
				// indicate that the temp file is no longer dirty
328
				// indicate that the temp file is no longer dirty
318
				properties.setDirty(false);
329
				properties.setDirty(false);
319
				editable.updateDirtyIndicator();
330
				editable.updateDirtyIndicator();
Lines 373-425 Link Here
373
			e.printStackTrace();
384
			e.printStackTrace();
374
		}
385
		}
375
	}
386
	}
376
	
377
	private IRemoteFile waitForTimestampToBeUpToDate(IRemoteFile remoteFile, long originalTimestamp, IProgressMonitor monitor)
378
	{
379
		IRemoteFileSubSystem fs = remoteFile.getParentRemoteFileSubSystem();
380
		String path = remoteFile.getAbsolutePath();
381
		try {
382
			long timestamp = originalTimestamp;
383
384
			boolean fileUpdated = false;
385
			boolean timestampChanging = true;
386
			
387
			int MAX_TIMES_CHECKED = 100; // make sure we don't wait indefinitely
388
			int timesChecked = 0;  
389
			
390
			while ((timestampChanging || !fileUpdated) && !monitor.isCanceled()){	// wait until the timestamp stops changing AND timestamp did change at least once		
391
				try {
392
					Thread.sleep(500); // sleep 
393
				}
394
				catch (InterruptedException e){				
395
				}
396
			
397
				// query the remote file again
398
				remoteFile.markStale(true);
399
				remoteFile = fs.getRemoteFileObject(path, monitor);
400
401
				// what's the timestamp now?
402
				long nextTimestamp = remoteFile.getLastModified();		
403
404
				timestampChanging = (timestamp != nextTimestamp);
405
406
				if (!fileUpdated){	// indicate the file has changed if the timestamp has			
407
					fileUpdated = timestampChanging;
408
				}
409
				
410
				timestamp = nextTimestamp;
411
				timesChecked++;
412
				
413
				if (timesChecked >= MAX_TIMES_CHECKED){ // we're not expecting this, but it's better to timeout than to hang on this
414
					SystemBasePlugin.logError("timeout waiting for timestamp after upload of "+ path); //$NON-NLS-1$
415
					return remoteFile;
416
				}
417
			}
418
		}
419
		catch (SystemMessageException e){
420
			
421
		}
422
		
423
		return remoteFile;
424
	}
425
}
387
}
(-)src/org/eclipse/rse/internal/files/ui/actions/SystemUploadConflictAction.java (-51 / +6 lines)
Lines 198-209 Link Here
198
            {
198
            {
199
            	IRemoteFileSubSystem fs = _remoteFile.getParentRemoteFileSubSystem();
199
            	IRemoteFileSubSystem fs = _remoteFile.getParentRemoteFileSubSystem();
200
            	SystemIFileProperties properties = new SystemIFileProperties(_tempFile);
200
            	SystemIFileProperties properties = new SystemIFileProperties(_tempFile);
201
            	long originalTimestamp = _remoteFile.getLastModified();
201
            	
202
            	// making sure we have the same version as is in the cache
203
            	_remoteFile = fs.getRemoteFileObject(_remoteFile.getAbsolutePath(), monitor);
202
            	
204
            	
203
                fs.upload(_tempFile.getLocation().makeAbsolute().toOSString(), _remoteFile, SystemEncodingUtil.ENCODING_UTF_8, monitor);
205
                fs.upload(_tempFile.getLocation().makeAbsolute().toOSString(), _remoteFile, SystemEncodingUtil.ENCODING_UTF_8, monitor);
204
206
205
                // wait for timestamp to update before re-fetching remote file
207
                // wait for timestamp to update before re-fetching remote file
206
                _remoteFile = waitForTimestampToBeUpToDate(_remoteFile, originalTimestamp, monitor);
208
                _remoteFile.markStale(true);
209
                _remoteFile = fs.getRemoteFileObject(_remoteFile.getAbsolutePath(), monitor);
207
210
208
                long ts = _remoteFile.getLastModified();
211
                long ts = _remoteFile.getLastModified();
209
                properties.setRemoteFileTimeStamp(ts);
212
                properties.setRemoteFileTimeStamp(ts);
Lines 220-275 Link Here
220
            }
223
            }
221
            return Status.OK_STATUS;
224
            return Status.OK_STATUS;
222
		}
225
		}
223
		
224
		private IRemoteFile waitForTimestampToBeUpToDate(IRemoteFile remoteFile, long originalTimestamp, IProgressMonitor monitor)
225
		{
226
			IRemoteFileSubSystem fs = remoteFile.getParentRemoteFileSubSystem();
227
			String path = remoteFile.getAbsolutePath();
228
			try {
229
				long timestamp = originalTimestamp;
230
231
				boolean fileUpdated = false;
232
				boolean timestampChanging = true;
233
				
234
				int MAX_TIMES_CHECKED = 100; // make sure we don't wait indefinitely
235
				int timesChecked = 0;  
236
				
237
				while ((timestampChanging || !fileUpdated) && !monitor.isCanceled()){	// wait until the timestamp stops changing AND timestamp did change at least once		
238
					try {
239
						Thread.sleep(500); // sleep 
240
					}
241
					catch (InterruptedException e){				
242
					}
243
				
244
					// query the remote file again
245
					remoteFile.markStale(true);
246
					remoteFile = fs.getRemoteFileObject(path, monitor);
247
248
					// what's the timestamp now?
249
					long nextTimestamp = remoteFile.getLastModified();		
250
251
					timestampChanging = (timestamp != nextTimestamp);
252
253
					if (!fileUpdated){	// indicate the file has changed if the timestamp has			
254
						fileUpdated = timestampChanging;
255
					}
256
					
257
					timestamp = nextTimestamp;
258
					timesChecked++;
259
					
260
					if (timesChecked >= MAX_TIMES_CHECKED){ // we're not expecting this, but it's better to timeout than to hang on this
261
						SystemBasePlugin.logError("timeout waiting for timestamp after upload of "+ path); //$NON-NLS-1$
262
						return remoteFile;
263
					}
264
				}
265
			}
266
			catch (SystemMessageException e){
267
				
268
			}
269
			
270
			return remoteFile;
271
		}	
272
	}
226
	}
227
		
273
228
274
	/**
229
	/**
275
	 * This is the default dialog used to handle upload conflicts
230
	 * This is the default dialog used to handle upload conflicts

Return to bug 249544