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

Collapse All | Expand All

(-)src/org/eclipse/rse/internal/services/files/ftp/FTPService.java (-104 / +113 lines)
Lines 58-63 Link Here
58
 * Martin Oberhuber (Wind River) - [192610] Fix thread safety for delete(), upload(), setReadOnly() operations
58
 * Martin Oberhuber (Wind River) - [192610] Fix thread safety for delete(), upload(), setReadOnly() operations
59
 * Martin Oberhuber (Wind River) - [199548] Avoid touching files on setReadOnly() if unnecessary
59
 * Martin Oberhuber (Wind River) - [199548] Avoid touching files on setReadOnly() if unnecessary
60
 * Javier Montalvo Orus (Symbian) - [199243] Renaming a file in an FTP-based EFS folder hangs all of Eclipse
60
 * Javier Montalvo Orus (Symbian) - [199243] Renaming a file in an FTP-based EFS folder hangs all of Eclipse
61
 * Martin Oberhuber (Wind River) - [203306] Fix Deadlock comparing two files on FTP
61
 ********************************************************************************/
62
 ********************************************************************************/
62
63
63
package org.eclipse.rse.internal.services.files.ftp;
64
package org.eclipse.rse.internal.services.files.ftp;
Lines 687-743 Link Here
687
		else{
688
		else{
688
				monitor = new NullProgressMonitor();
689
				monitor = new NullProgressMonitor();
689
		}
690
		}
690
		
691
691
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
692
		MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
692
		{
693
		progressMonitor.init(0, localFile.getName(), remoteFile, localFile.length());
693
			try
694
		FileInputStream input = null;
695
		OutputStream output = null;
696
697
		try {
698
			if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
694
			{
699
			{
695
				MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
700
				try
696
				
697
				FTPClient ftpClient = getFTPClient();
698
				clearCache(remoteParent);
699
				ftpClient.changeWorkingDirectory(remoteParent);
700
				setFileType(isBinary);
701
				
702
				FileInputStream input =  new FileInputStream(localFile);
703
				OutputStream output = ftpClient.storeFileStream(remoteFile);
704
				
705
				progressMonitor.init(0, localFile.getName(), remoteFile, localFile.length());
706
				long bytes=0;
707
				byte[] buffer = new byte[4096];
708
				
709
				int readCount;
710
				while((readCount = input.read(buffer)) > 0)
711
				{
701
				{
712
					bytes+=readCount;
702
					FTPClient ftpClient = getFTPClient();
713
					output.write(buffer, 0, readCount);
703
					clearCache(remoteParent);
714
					progressMonitor.count(readCount);
704
					ftpClient.changeWorkingDirectory(remoteParent);
715
					if (monitor!=null){
705
					setFileType(isBinary);
716
						if (monitor.isCanceled()) {
706
					
717
							retValue = false;
707
					input =  new FileInputStream(localFile);
718
							break;
708
					output = ftpClient.storeFileStream(remoteFile);
719
						}	
709
					if (output!=null) {
710
						long bytes=0;
711
						byte[] buffer = new byte[4096];
712
						
713
						int readCount;
714
						while((readCount = input.read(buffer)) > 0)
715
						{
716
							bytes+=readCount;
717
							output.write(buffer, 0, readCount);
718
							progressMonitor.count(readCount);
719
							if (monitor!=null){
720
								if (monitor.isCanceled()) {
721
									retValue = false;
722
									break;
723
								}	
724
							}
725
						}
726
						if (retValue) {
727
							output.flush();
728
						}
729
						ftpClient.completePendingCommand();
730
					} else {
731
						throw new Exception(ftpClient.getReplyString());
732
					}
733
					if(retValue==false)	{
734
						ftpClient.deleteFile(remoteFile);
720
					}
735
					}
721
				}
736
				}
722
				
737
				finally {
723
				input.close();
738
					_commandMutex.release();
724
				output.flush();
739
					try {
725
				output.close();
740
						if (input!=null) input.close();
726
				
741
					} finally {
727
				ftpClient.completePendingCommand();
742
						if (output!=null) output.close(); 
728
				
743
					}
729
				if(retValue==false)	{
744
			    }
730
					ftpClient.deleteFile(remoteFile);
731
				}
732
				
733
				progressMonitor.end();
734
			}
745
			}
735
			catch (Exception e)
746
		} catch(Exception e) {
736
			{
747
			throw new RemoteFileIOException(e);
737
				throw new RemoteFileIOException(e);
748
		} finally {
738
			} finally {
749
			progressMonitor.end();
739
				_commandMutex.release();
740
		    }
741
		}
750
		}
742
		
751
		
743
		return retValue;
752
		return retValue;
Lines 800-877 Link Here
800
		}
809
		}
801
		
810
		
802
		IHostFile remoteHostFile = getFile(remoteParent, remoteFile, monitor);
811
		IHostFile remoteHostFile = getFile(remoteParent, remoteFile, monitor);
812
		MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
813
		progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize());
814
		OutputStream output = null;
815
		InputStream input = null;
803
		
816
		
804
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
817
		try {
805
		{
818
			if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
806
			try
807
			{
819
			{
808
				FTPClient ftpClient = getFTPClient();
820
				try
809
				
810
				MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor);
811
				
812
				OutputStream output = null;
813
				InputStream input = null;
814
				
815
				ftpClient.changeWorkingDirectory(remoteParent);
816
				setFileType(isBinary);
817
				
818
				input = ftpClient.retrieveFileStream(remoteFile);
819
				
820
				if(input != null)
821
				{
821
				{
822
					if (!localFile.exists())
822
					FTPClient ftpClient = getFTPClient();
823
					ftpClient.changeWorkingDirectory(remoteParent);
824
					setFileType(isBinary);
825
					
826
					input = ftpClient.retrieveFileStream(remoteFile);
827
					
828
					if(input != null)
823
					{
829
					{
824
						File localParentFile = localFile.getParentFile();
830
						if (!localFile.exists())
825
						if (!localParentFile.exists())
831
						{
832
							File localParentFile = localFile.getParentFile();
833
							if (!localParentFile.exists())
834
							{
835
								localParentFile.mkdirs();
836
							}
837
							localFile.createNewFile();
838
						}
839
						
840
						output = new FileOutputStream(localFile);
841
						byte[] buffer = new byte[4096];
842
						int readCount;
843
						while((readCount = input.read(buffer)) > 0)
826
						{
844
						{
827
							localParentFile.mkdirs();
845
							output.write(buffer, 0, readCount);
846
							progressMonitor.count(readCount);
847
							if (monitor!=null){
848
								if (monitor.isCanceled()) {
849
									retValue = false;
850
									break;
851
								}	
852
							}
828
						}
853
						}
829
						localFile.createNewFile();
854
						
855
						if (retValue) output.flush();
856
						
857
						ftpClient.completePendingCommand();
858
						
830
					}
859
					}
831
					
860
					else
832
					output = new FileOutputStream(localFile);
833
					progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize());
834
					byte[] buffer = new byte[4096];
835
					int readCount;
836
					while((readCount = input.read(buffer)) > 0)
837
					{
861
					{
838
						output.write(buffer, 0, readCount);
862
						throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()));
839
						progressMonitor.count(readCount);
840
						if (monitor!=null){
841
							if (monitor.isCanceled()) {
842
								retValue = false;
843
								break;
844
							}	
845
						}
846
					}
863
					}
847
					
848
					progressMonitor.end();
849
					
850
					output.flush();
851
					input.close();
852
					output.close();
853
					
854
					ftpClient.completePendingCommand();
855
					
856
				}
864
				}
857
				else
865
				finally
858
				{
866
				{
859
					throw new RemoteFileIOException(new Exception(ftpClient.getReplyString()));
867
					_commandMutex.release();
868
					try { 
869
						if (input!=null) input.close(); 
870
					} finally {
871
						if (output!=null) output.close();
872
					}
860
				}
873
				}
861
			}
874
			}
862
			catch (FileNotFoundException e)
875
		} catch (FileNotFoundException e) {
863
			{
876
			throw new RemoteFileIOException(e);
864
				throw new RemoteFileIOException(e);
877
		} catch (IOException e) {
865
			}
878
			throw new RemoteFileIOException(e);
866
			catch (IOException e)
879
		} finally {
867
			{
880
			progressMonitor.end();
868
				throw new RemoteFileIOException(e);
869
			} 
870
			finally
871
			{
872
				_commandMutex.release();
873
			}
874
		}
881
		}
882
		
875
		return retValue;
883
		return retValue;
876
	}
884
	}
877
	
885
	
Lines 957-962 Link Here
957
				_commandMutex.release();
965
				_commandMutex.release();
958
			}
966
			}
959
		}
967
		}
968
		progressMonitor.end();
960
969
961
		return hasSucceeded;
970
		return hasSucceeded;
962
	}
971
	}

Return to bug 203306