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

Collapse All | Expand All

(-)src/org/eclipse/rse/internal/services/files/ftp/FTPService.java (-60 / +70 lines)
Lines 55-60 Link Here
55
 * Javier Montalvo Orus (Symbian) - [195830] RSE performs unnecessary remote list commands
55
 * Javier Montalvo Orus (Symbian) - [195830] RSE performs unnecessary remote list commands
56
 * Martin Oberhuber (Wind River) - [198638] Fix invalid caching
56
 * Martin Oberhuber (Wind River) - [198638] Fix invalid caching
57
 * Martin Oberhuber (Wind River) - [198645] Fix case sensitivity issues
57
 * Martin Oberhuber (Wind River) - [198645] Fix case sensitivity issues
58
 * Martin Oberhuber (Wind River) - [192610] Fix thread safety for delete(), upload(), setReadOnly() operations
58
 ********************************************************************************/
59
 ********************************************************************************/
59
60
60
package org.eclipse.rse.internal.services.files.ftp;
61
package org.eclipse.rse.internal.services.files.ftp;
Lines 359-364 Link Here
359
			_userHome = '/'+_userHome.substring(0,_userHome.lastIndexOf(']'));
360
			_userHome = '/'+_userHome.substring(0,_userHome.lastIndexOf(']'));
360
		}
361
		}
361
		
362
		
363
		//Just to be safe
364
		synchronized (_fCachePreviousFiles) {
365
			_fCachePreviousFiles.clear();
366
		}
362
	}
367
	}
363
	
368
	
364
	public void disconnect()
369
	public void disconnect()
Lines 422-427 Link Here
422
	
427
	
423
	/**
428
	/**
424
	 * Return FTPHostFile object for a given parent dir and file name.
429
	 * Return FTPHostFile object for a given parent dir and file name.
430
	 * This is different than {@link #getFile(String, String, IProgressMonitor)}
431
	 * in order to ensure we always return proper FTPHostFile type.
432
	 * 
425
	 * @see org.eclipse.rse.services.files.IFileService#getFile(String, String, IProgressMonitor)
433
	 * @see org.eclipse.rse.services.files.IFileService#getFile(String, String, IProgressMonitor)
426
	 */
434
	 */
427
	protected FTPHostFile getFileInternal(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
435
	protected FTPHostFile getFileInternal(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException
Lines 720-726 Link Here
720
			 bos.close();
728
			 bos.close();
721
			 
729
			 
722
			 if(retValue == true){
730
			 if(retValue == true){
723
				setFileType(isBinary);
724
				retValue = upload(tempFile, remoteParent, remoteFile, isBinary, "", hostEncoding, monitor); //$NON-NLS-1$
731
				retValue = upload(tempFile, remoteParent, remoteFile, isBinary, "", hostEncoding, monitor); //$NON-NLS-1$
725
			 }
732
			 }
726
			 
733
			 
Lines 859-907 Link Here
859
	public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException {
866
	public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException {
860
		boolean hasSucceeded = false;
867
		boolean hasSucceeded = false;
861
		
868
		
862
		FTPClient ftpClient = getFTPClient();
863
		
864
		MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
869
		MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
865
		
866
		progressMonitor.init(FTPServiceResources.FTP_File_Service_Deleting_Task+fileName, 1);  
870
		progressMonitor.init(FTPServiceResources.FTP_File_Service_Deleting_Task+fileName, 1);  
867
		
871
		
868
		IHostFile file = getFile(remoteParent, fileName, monitor);
872
		IHostFile file = getFile(remoteParent, fileName, monitor);
869
			
873
			
870
		boolean isFile = file.isFile();
874
		boolean isFile = file.isFile();
871
		
875
		
872
		try {
876
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) {
873
			hasSucceeded = FTPReply.isPositiveCompletion(ftpClient.cwd(remoteParent));
877
			try {
874
			
878
				FTPClient ftpClient = getFTPClient();
875
			if(hasSucceeded)
879
				
876
			{
880
				hasSucceeded = FTPReply.isPositiveCompletion(ftpClient.cwd(remoteParent));
877
				if(isFile)
881
				
882
				if(hasSucceeded)
878
				{
883
				{
879
					hasSucceeded = ftpClient.deleteFile(fileName);
884
					if(isFile)
885
					{
886
						hasSucceeded = ftpClient.deleteFile(fileName);
887
					}
888
					else
889
					{
890
						hasSucceeded = ftpClient.removeDirectory(fileName);
891
					}
892
				}
893
				
894
				if(!hasSucceeded){
895
					throw new Exception(ftpClient.getReplyString()+" ("+fileName+")"); //$NON-NLS-1$ //$NON-NLS-2$
880
				}
896
				}
881
				else
897
				else
882
				{
898
				{
883
					hasSucceeded = ftpClient.removeDirectory(fileName);
899
					progressMonitor.worked(1);
884
				}
900
				}
901
				
885
			}
902
			}
886
			
903
			catch (Exception e) {
887
			if(!hasSucceeded){
904
				if(isFile){
888
				throw new Exception(ftpClient.getReplyString()+" ("+fileName+")"); //$NON-NLS-1$ //$NON-NLS-2$
905
					throw new RemoteFileIOException(e);
889
			}
906
				}
890
			else
907
				else{
891
			{
908
					throw new RemoteFolderNotEmptyException(e);
892
				progressMonitor.worked(1);
909
				}
893
			}
910
			} finally {
894
			
911
				_commandMutex.release();
895
		}
896
		catch (Exception e) {
897
			if(isFile){
898
				throw new RemoteFileIOException(e);
899
			}
900
			else{
901
				throw new RemoteFolderNotEmptyException(e);
902
			}
912
			}
903
				
904
				
905
		}
913
		}
906
914
907
		return hasSucceeded;
915
		return hasSucceeded;
Lines 1073-1079 Link Here
1073
		return true;
1081
		return true;
1074
	}
1082
	}
1075
	
1083
	
1076
	
1084
	/**
1085
	 * Internal method to list files.
1086
	 * MUST ALWAYS be called from _commandMutex protected region.
1087
	 */
1077
	private boolean listFiles(IProgressMonitor monitor) throws Exception
1088
	private boolean listFiles(IProgressMonitor monitor) throws Exception
1078
	{
1089
	{
1079
		boolean result = true;
1090
		boolean result = true;
Lines 1254-1293 Link Here
1254
		}
1265
		}
1255
		
1266
		
1256
		permissions = userPermissions * 100 + groupPermissions * 10 + otherPermissions;
1267
		permissions = userPermissions * 100 + groupPermissions * 10 + otherPermissions;
1257
		
1268
1258
		try {
1269
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) {
1259
			result =_ftpClient.sendSiteCommand("CHMOD "+permissions+" "+file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
1270
			try {
1260
		} catch (IOException e) {
1271
				result =_ftpClient.sendSiteCommand("CHMOD "+permissions+" "+file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
1261
			result = false;
1272
			} catch (IOException e) {
1262
		} 
1273
				result = false;
1274
			} finally {
1275
				_commandMutex.release();
1276
			}
1277
		}
1263
		
1278
		
1264
		return result;
1279
		return result;
1265
	}
1280
	}
1266
1281
1267
	/**
1282
	/*
1268
	 * Gets the input stream to access the contents of a remote file.
1283
	 * (non-Javadoc)
1269
	 * @since 2.0 
1270
	 * @see org.eclipse.rse.services.files.AbstractFileService#getInputStream(java.lang.String, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
1284
	 * @see org.eclipse.rse.services.files.AbstractFileService#getInputStream(java.lang.String, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
1271
	 */
1285
	 */
1272
	public InputStream getInputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException {
1286
	public InputStream getInputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException {
1273
		
1287
		
1274
		if (monitor != null){
1288
		if (monitor != null && monitor.isCanceled()){
1275
			
1289
			throw new RemoteFileCancelledException();
1276
			if (monitor.isCanceled()) {
1277
				return null;
1278
			}	
1279
		}
1290
		}
1280
1291
1281
		InputStream stream = null;
1292
		InputStream stream = null;
1282
		
1293
		
1283
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
1294
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
1284
		{
1295
		{
1285
		
1286
			FTPClient ftpClient = getFTPClient();
1296
			FTPClient ftpClient = getFTPClient();
1287
		
1288
			try {
1297
			try {
1289
				
1290
				
1291
				ftpClient.changeWorkingDirectory(remoteParent);
1298
				ftpClient.changeWorkingDirectory(remoteParent);
1292
				setFileType(isBinary);
1299
				setFileType(isBinary);
1293
				stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient);
1300
				stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient);
Lines 1295-1320 Link Here
1295
			catch (Exception e) {			
1302
			catch (Exception e) {			
1296
				throw new RemoteFileIOException(e);
1303
				throw new RemoteFileIOException(e);
1297
			}finally {
1304
			}finally {
1298
			_commandMutex.release();
1305
				//TODO I am not 100% sure but I _think_ that the _commandMutex
1306
				//may only be released once reading the stream is complete,
1307
				//since in FTPBufferedInputStream.close() a pending command
1308
				//is being sent.
1309
				//After all, the safer solution would be to have a separate
1310
				//FTP client connection to the remote for the download, such 
1311
				//that dir channel remains free. See bug #198636
1312
				_commandMutex.release();
1299
			}
1313
			}
1314
		} else {
1315
			throw new RemoteFileCancelledException();
1300
		}
1316
		}
1301
		
1302
		
1303
		return stream;
1317
		return stream;
1304
	}
1318
	}
1305
1319
1306
	/**
1320
	/*
1307
	 * Gets the output stream to write to a remote file.
1321
	 * (non-Javadoc)
1308
	 * @since 2.0
1309
	 * @see org.eclipse.rse.services.files.AbstractFileService#getOutputStream(java.lang.String, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
1322
	 * @see org.eclipse.rse.services.files.AbstractFileService#getOutputStream(java.lang.String, java.lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
1310
	 */
1323
	 */
1311
	public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException {
1324
	public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException {
1312
		
1325
		
1313
		if (monitor != null){
1326
		if (monitor != null && monitor.isCanceled()){
1314
			
1327
			throw new RemoteFileCancelledException();
1315
			if (monitor.isCanceled()) {
1316
				return null;
1317
			}	
1318
		}
1328
		}
1319
		
1329
		
1320
		OutputStream stream = null;
1330
		OutputStream stream = null;

Return to bug 192610