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 |
output.close(); |
730 |
output = null; |
731 |
ftpClient.completePendingCommand(); |
732 |
} else { |
733 |
throw new Exception(ftpClient.getReplyString()); |
734 |
} |
735 |
if(retValue==false) { |
736 |
ftpClient.deleteFile(remoteFile); |
720 |
} |
737 |
} |
721 |
} |
738 |
} |
722 |
|
739 |
finally { |
723 |
input.close(); |
740 |
_commandMutex.release(); |
724 |
output.flush(); |
741 |
try { |
725 |
output.close(); |
742 |
if (input!=null) input.close(); |
726 |
|
743 |
} finally { |
727 |
ftpClient.completePendingCommand(); |
744 |
if (output!=null) output.close(); |
728 |
|
745 |
} |
729 |
if(retValue==false) { |
746 |
} |
730 |
ftpClient.deleteFile(remoteFile); |
|
|
731 |
} |
732 |
|
733 |
progressMonitor.end(); |
734 |
} |
747 |
} |
735 |
catch (Exception e) |
748 |
} catch(Exception e) { |
736 |
{ |
749 |
throw new RemoteFileIOException(e); |
737 |
throw new RemoteFileIOException(e); |
750 |
} finally { |
738 |
} finally { |
751 |
progressMonitor.end(); |
739 |
_commandMutex.release(); |
|
|
740 |
} |
741 |
} |
752 |
} |
742 |
|
753 |
|
743 |
return retValue; |
754 |
return retValue; |
Lines 800-877
Link Here
|
800 |
} |
811 |
} |
801 |
|
812 |
|
802 |
IHostFile remoteHostFile = getFile(remoteParent, remoteFile, monitor); |
813 |
IHostFile remoteHostFile = getFile(remoteParent, remoteFile, monitor); |
|
|
814 |
MyProgressMonitor progressMonitor = new MyProgressMonitor(monitor); |
815 |
progressMonitor.init(0, remoteFile, localFile.getName(), remoteHostFile.getSize()); |
816 |
OutputStream output = null; |
817 |
InputStream input = null; |
803 |
|
818 |
|
804 |
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) |
819 |
try { |
805 |
{ |
820 |
if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) |
806 |
try |
|
|
807 |
{ |
821 |
{ |
808 |
FTPClient ftpClient = getFTPClient(); |
822 |
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 |
{ |
823 |
{ |
822 |
if (!localFile.exists()) |
824 |
FTPClient ftpClient = getFTPClient(); |
|
|
825 |
ftpClient.changeWorkingDirectory(remoteParent); |
826 |
setFileType(isBinary); |
827 |
|
828 |
input = ftpClient.retrieveFileStream(remoteFile); |
829 |
|
830 |
if(input != null) |
823 |
{ |
831 |
{ |
824 |
File localParentFile = localFile.getParentFile(); |
832 |
if (!localFile.exists()) |
825 |
if (!localParentFile.exists()) |
833 |
{ |
|
|
834 |
File localParentFile = localFile.getParentFile(); |
835 |
if (!localParentFile.exists()) |
836 |
{ |
837 |
localParentFile.mkdirs(); |
838 |
} |
839 |
localFile.createNewFile(); |
840 |
} |
841 |
|
842 |
output = new FileOutputStream(localFile); |
843 |
byte[] buffer = new byte[4096]; |
844 |
int readCount; |
845 |
while((readCount = input.read(buffer)) > 0) |
826 |
{ |
846 |
{ |
827 |
localParentFile.mkdirs(); |
847 |
output.write(buffer, 0, readCount); |
|
|
848 |
progressMonitor.count(readCount); |
849 |
if (monitor!=null){ |
850 |
if (monitor.isCanceled()) { |
851 |
retValue = false; |
852 |
break; |
853 |
} |
854 |
} |
828 |
} |
855 |
} |
829 |
localFile.createNewFile(); |
856 |
|
|
|
857 |
if (retValue) output.flush(); |
858 |
input.close(); |
859 |
input = null; |
860 |
ftpClient.completePendingCommand(); |
861 |
|
830 |
} |
862 |
} |
831 |
|
863 |
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 |
{ |
864 |
{ |
838 |
output.write(buffer, 0, readCount); |
865 |
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 |
} |
866 |
} |
847 |
|
|
|
848 |
progressMonitor.end(); |
849 |
|
850 |
output.flush(); |
851 |
input.close(); |
852 |
output.close(); |
853 |
|
854 |
ftpClient.completePendingCommand(); |
855 |
|
856 |
} |
867 |
} |
857 |
else |
868 |
finally |
858 |
{ |
869 |
{ |
859 |
throw new RemoteFileIOException(new Exception(ftpClient.getReplyString())); |
870 |
_commandMutex.release(); |
|
|
871 |
try { |
872 |
if (input!=null) input.close(); |
873 |
} finally { |
874 |
if (output!=null) output.close(); |
875 |
} |
860 |
} |
876 |
} |
861 |
} |
877 |
} |
862 |
catch (FileNotFoundException e) |
878 |
} catch (FileNotFoundException e) { |
863 |
{ |
879 |
throw new RemoteFileIOException(e); |
864 |
throw new RemoteFileIOException(e); |
880 |
} catch (IOException e) { |
865 |
} |
881 |
throw new RemoteFileIOException(e); |
866 |
catch (IOException e) |
882 |
} finally { |
867 |
{ |
883 |
progressMonitor.end(); |
868 |
throw new RemoteFileIOException(e); |
|
|
869 |
} |
870 |
finally |
871 |
{ |
872 |
_commandMutex.release(); |
873 |
} |
874 |
} |
884 |
} |
|
|
885 |
|
875 |
return retValue; |
886 |
return retValue; |
876 |
} |
887 |
} |
877 |
|
888 |
|
Lines 957-962
Link Here
|
957 |
_commandMutex.release(); |
968 |
_commandMutex.release(); |
958 |
} |
969 |
} |
959 |
} |
970 |
} |
|
|
971 |
progressMonitor.end(); |
960 |
|
972 |
|
961 |
return hasSucceeded; |
973 |
return hasSucceeded; |
962 |
} |
974 |
} |