Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 78636 Details for
Bug 203500
[ssh][ftp][encodings] Error creating a folder or file with non-ASCII characters (converted to ?)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch to support encodings in SSH Sftp files and paths
patch203500_sftpEncodings.diff.txt (text/plain), 14.46 KB, created by
Martin Oberhuber
on 2007-09-18 07:59:30 EDT
(
hide
)
Description:
Patch to support encodings in SSH Sftp files and paths
Filename:
MIME Type:
Creator:
Martin Oberhuber
Created:
2007-09-18 07:59:30 EDT
Size:
14.46 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rse.connectorservice.ssh >Index: src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java >=================================================================== >RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java,v >retrieving revision 1.15 >diff -u -r1.15 SshConnectorService.java >--- src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java 3 Aug 2007 10:37:42 -0000 1.15 >+++ src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java 18 Sep 2007 11:58:44 -0000 >@@ -13,6 +13,7 @@ > * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry > * Martin Oberhuber (Wind River) - [186761] make the port setting configurable > * Martin Oberhuber (Wind River) - [198790] make SSH createSession() protected >+ * Martin Oberhuber (Wind River) - [203500] Support encodings for SSH Sftp paths > *******************************************************************************/ > > package org.eclipse.rse.internal.connectorservice.ssh; >@@ -61,6 +62,8 @@ > private static final int CONNECT_DEFAULT_TIMEOUT = 60; //seconds > private Session session; > private SessionLostHandler fSessionLostHandler; >+ /** Indicates the default string encoding on this platform */ >+ private static String _defaultEncoding = new java.io.InputStreamReader(new java.io.ByteArrayInputStream(new byte[0])).getEncoding(); > > public SshConnectorService(IHost host) { > super(SshConnectorResources.SshConnectorService_Name, SshConnectorResources.SshConnectorService_Description, host, SSH_DEFAULT_PORT); >@@ -209,6 +212,15 @@ > public Session getSession() { > return session; > } >+ >+ public String getControlEncoding() { >+ //TODO this code should be in IHost >+ String encoding = getHost().getDefaultEncoding(false); >+ if (encoding==null) encoding = getHost().getDefaultEncoding(true); >+ if (encoding==null) encoding = _defaultEncoding; >+ //</code to be in IHost> >+ return encoding; >+ } > > /** > * Handle session-lost events. >#P org.eclipse.rse.services.ssh >Index: src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java >=================================================================== >RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java,v >retrieving revision 1.22 >diff -u -r1.22 SftpFileService.java >--- src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java 14 Sep 2007 20:51:42 -0000 1.22 >+++ src/org/eclipse/rse/internal/services/ssh/files/SftpFileService.java 18 Sep 2007 11:58:45 -0000 >@@ -14,6 +14,7 @@ > * Martin Oberhuber (Wind River) - [199548] Avoid touching files on setReadOnly() if unnecessary > * Benjamin Muskalla (b.muskalla@gmx.net) - [174690][ssh] cannot delete symbolic links on remote systems > * Martin Oberhuber (Wind River) - [203490] Fix NPE in SftpService.getUserHome() >+ * Martin Oberhuber (Wind River) - [203500] Support encodings for SSH Sftp paths > *******************************************************************************/ > > package org.eclipse.rse.internal.services.ssh.files; >@@ -26,6 +27,7 @@ > import java.io.IOException; > import java.io.InputStream; > import java.io.OutputStream; >+import java.io.UnsupportedEncodingException; > import java.text.MessageFormat; > import java.util.ArrayList; > import java.util.List; >@@ -139,7 +141,11 @@ > private ChannelSftp fChannelSftp; > private String fUserHome; > private Mutex fDirChannelMutex = new Mutex(); >- private long fDirChannelTimeout = 5000; //max.5 seconds to obtain dir channel >+ private long fDirChannelTimeout = 5000; //max.5 seconds to obtain dir channel >+ /** Client-desired encoding for file and path names */ >+ private String fControlEncoding = null; >+ /** Indicates the default string encoding on this platform */ >+ private static String defaultEncoding = new java.io.InputStreamReader(new java.io.ByteArrayInputStream(new byte[0])).getEncoding(); > > // public SftpFileService(SshConnectorService conn) { > // fConnector = conn; >@@ -149,6 +155,50 @@ > fSessionProvider = sessionProvider; > } > >+ public void setControlEncoding(String encoding) { >+ fControlEncoding = encoding; >+ } >+ >+ /** >+ * Encode String with requested user encoding, in case it differs from Platform default encoding. >+ * @param s String to encode >+ * @return encoded String >+ * @throws SystemMessageException >+ */ >+ protected String recode(String s) throws SystemMessageException { >+ if (fControlEncoding==null) { >+ return s; >+ } else if (fControlEncoding.equals(defaultEncoding)) { >+ return s; >+ } >+ try { >+ byte[] bytes = s.getBytes(fControlEncoding); >+ return new String(bytes); >+ } catch(UnsupportedEncodingException e) { >+ throw makeSystemMessageException(e); >+ } >+ } >+ >+ /** >+ * Decode String (sftp result) with requested user encoding, in case it differs from Platform default encoding. >+ * @param s String to decode >+ * @return decoded String >+ * @throws SystemMessageException >+ */ >+ protected String decode(String s) throws SystemMessageException { >+ if (fControlEncoding==null) { >+ return s; >+ } else if (fControlEncoding.equals(defaultEncoding)) { >+ return s; >+ } >+ try { >+ byte[] bytes = s.getBytes(); //original bytes sent by SSH >+ return new String(bytes, fControlEncoding); >+ } catch(UnsupportedEncodingException e) { >+ throw makeSystemMessageException(e); >+ } >+ } >+ > public String getName() { > return SshServiceResources.SftpFileService_Name; > } >@@ -164,7 +214,8 @@ > Channel channel=session.openChannel("sftp"); //$NON-NLS-1$ > channel.connect(); > fChannelSftp=(ChannelSftp)channel; >- fUserHome = fChannelSftp.pwd(); >+ setControlEncoding(fSessionProvider.getControlEncoding()); >+ fUserHome = decode(fChannelSftp.pwd()); > Activator.trace("SftpFileService.connected"); //$NON-NLS-1$ > } catch(Exception e) { > Activator.trace("SftpFileService.connecting failed: "+e.toString()); //$NON-NLS-1$ >@@ -256,7 +307,7 @@ > SftpATTRS attrs = null; > if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { > try { >- attrs = getChannel("SftpFileService.getFile: "+fileName).stat(remoteParent+'/'+fileName); //$NON-NLS-1$ >+ attrs = getChannel("SftpFileService.getFile: "+fileName).stat(recode(remoteParent+'/'+fileName)); //$NON-NLS-1$ > Activator.trace("SftpFileService.getFile <--"); //$NON-NLS-1$ > node = makeHostFile(remoteParent, fileName, attrs); > } catch(Exception e) { >@@ -304,12 +355,12 @@ > List results = new ArrayList(); > if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { > try { >- Vector vv=getChannel("SftpFileService.internalFetch: "+parentPath).ls(parentPath); //$NON-NLS-1$ >+ Vector vv=getChannel("SftpFileService.internalFetch: "+parentPath).ls(recode(parentPath)); //$NON-NLS-1$ > for(int ii=0; ii<vv.size(); ii++) { > Object obj=vv.elementAt(ii); > if(obj instanceof ChannelSftp.LsEntry){ > ChannelSftp.LsEntry lsEntry = (ChannelSftp.LsEntry)obj; >- String fileName = lsEntry.getFilename(); >+ String fileName = decode(lsEntry.getFilename()); > if (".".equals(fileName) || "..".equals(fileName)) { //$NON-NLS-1$ //$NON-NLS-2$ > //don't show the trivial names > continue; >@@ -353,15 +404,15 @@ > // try { > // //Note: readlink() is supported only with jsch-0.1.29 or higher. > // //By catching the exception we remain backward compatible. >- // linkTarget=getChannel("makeHostFile.readlink").readlink(node.getAbsolutePath()); //$NON-NLS-1$ >+ // linkTarget=getChannel("makeHostFile.readlink").readlink(recode(node.getAbsolutePath())); //$NON-NLS-1$ > // //TODO: Classify the type of resource linked to as file, folder or broken link > // } catch(Exception e) {} > //check if the link points to a directory > try { >- getChannel("makeHostFile.chdir").cd(parentPath+'/'+fileName); //$NON-NLS-1$ >- linkTarget=getChannel("makeHostFile.chdir").pwd(); //$NON-NLS-1$ >+ getChannel("makeHostFile.chdir").cd(recode(parentPath+'/'+fileName)); //$NON-NLS-1$ >+ linkTarget=decode(getChannel("makeHostFile.chdir").pwd()); //$NON-NLS-1$ > if (linkTarget!=null && !linkTarget.equals(parentPath+'/'+fileName)) { >- attrsTarget = getChannel("SftpFileService.getFile").stat(linkTarget); //$NON-NLS-1$ >+ attrsTarget = getChannel("SftpFileService.getFile").stat(recode(linkTarget)); //$NON-NLS-1$ > } else { > linkTarget=null; > } >@@ -601,12 +652,12 @@ > if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { > try { > String fullPath = remoteParent + '/' + fileName; >- OutputStream os = getChannel("SftpFileService.createFile").put(fullPath); //$NON-NLS-1$ >+ OutputStream os = getChannel("SftpFileService.createFile").put(recode(fullPath)); //$NON-NLS-1$ > //TODO workaround bug 153118: write a single space > //since jsch hangs when trying to close the stream without writing > os.write(32); > os.close(); >- SftpATTRS attrs = getChannel("SftpFileService.createFile.stat").stat(fullPath); //$NON-NLS-1$ >+ SftpATTRS attrs = getChannel("SftpFileService.createFile.stat").stat(recode(fullPath)); //$NON-NLS-1$ > result = makeHostFile(remoteParent, fileName, attrs); > Activator.trace("SftpFileService.createFile ok"); //$NON-NLS-1$ > } catch (Exception e) { >@@ -627,8 +678,8 @@ > if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { > try { > String fullPath = remoteParent + '/' + folderName; >- getChannel("SftpFileService.createFolder").mkdir(fullPath); //$NON-NLS-1$ >- SftpATTRS attrs = getChannel("SftpFileService.createFolder.stat").stat(fullPath); //$NON-NLS-1$ >+ getChannel("SftpFileService.createFolder").mkdir(recode(fullPath)); //$NON-NLS-1$ >+ SftpATTRS attrs = getChannel("SftpFileService.createFolder.stat").stat(recode(fullPath)); //$NON-NLS-1$ > result = makeHostFile(remoteParent, folderName, attrs); > Activator.trace("SftpFileService.createFolder ok"); //$NON-NLS-1$ > } catch (Exception e) { >@@ -652,12 +703,12 @@ > String fullPath = remoteParent + '/' + fileName; > SftpATTRS attrs = null; > try { >- attrs = getChannel("SftpFileService.delete").lstat(fullPath); //$NON-NLS-1$ >+ attrs = getChannel("SftpFileService.delete").lstat(recode(fullPath)); //$NON-NLS-1$ > } catch (SftpException e) { > //bug 154419: test for dangling symbolic link > if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) { > //simply try to delete --> if it really doesnt exist, this will throw an exception >- getChannel("SftpFileService.delete.rm").rm(fullPath); //$NON-NLS-1$ >+ getChannel("SftpFileService.delete.rm").rm(recode(fullPath)); //$NON-NLS-1$ > } else { > throw e; > } >@@ -667,7 +718,7 @@ > ok=true; > } else if (attrs.isDir()) { > try { >- getChannel("SftpFileService.delete.rmdir").rmdir(fullPath); //$NON-NLS-1$ >+ getChannel("SftpFileService.delete.rmdir").rmdir(recode(fullPath)); //$NON-NLS-1$ > ok=true; > } catch(SftpException e) { > if(e.id==ChannelSftp.SSH_FX_FAILURE) { >@@ -681,7 +732,7 @@ > } > } > } else { >- getChannel("SftpFileService.delete.rm").rm(fullPath); //$NON-NLS-1$ >+ getChannel("SftpFileService.delete.rm").rm(recode(fullPath)); //$NON-NLS-1$ > ok=true; > } > Activator.trace("SftpFileService.delete ok"); //$NON-NLS-1$ >@@ -702,7 +753,7 @@ > try { > String fullPathOld = remoteParent + '/' + oldName; > String fullPathNew = remoteParent + '/' + newName; >- getChannel("SftpFileService.rename").rename(fullPathOld, fullPathNew); //$NON-NLS-1$ >+ getChannel("SftpFileService.rename").rename(recode(fullPathOld), recode(fullPathNew)); //$NON-NLS-1$ > ok=true; > Activator.trace("SftpFileService.rename ok"); //$NON-NLS-1$ > } catch (Exception e) { >@@ -849,7 +900,7 @@ > if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { > try { > String path = parent + '/' + name; >- getChannel("SftpFileService.setLastModified").setMtime(path, (int)(timestamp/1000)); //$NON-NLS-1$ >+ getChannel("SftpFileService.setLastModified").setMtime(recode(path), (int)(timestamp/1000)); //$NON-NLS-1$ > ok=true; > Activator.trace("SftpFileService.setLastModified ok"); //$NON-NLS-1$ > } catch (Exception e) { >@@ -868,7 +919,7 @@ > if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) { > try { > String path = parent + '/' + name; >- SftpATTRS attr = getChannel("SftpFileService.setReadOnly").stat(path); //$NON-NLS-1$ >+ SftpATTRS attr = getChannel("SftpFileService.setReadOnly").stat(recode(path)); //$NON-NLS-1$ > int permOld = attr.getPermissions(); > int permNew = permOld; > if (readOnly) { >@@ -879,7 +930,7 @@ > if (permNew != permOld) { > //getChannel("SftpFileService.setReadOnly").chmod(permNew, path); //$NON-NLS-1$ > attr.setPERMISSIONS(permNew); >- getChannel("SftpFileService.setReadOnly").setStat(path, attr); //$NON-NLS-1$ >+ getChannel("SftpFileService.setReadOnly").setStat(recode(path), attr); //$NON-NLS-1$ > ok=true; > Activator.trace("SftpFileService.setReadOnly ok"); //$NON-NLS-1$ > } else { >Index: src/org/eclipse/rse/internal/services/ssh/ISshSessionProvider.java >=================================================================== >RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/internal/services/ssh/ISshSessionProvider.java,v >retrieving revision 1.2 >diff -u -r1.2 ISshSessionProvider.java >--- src/org/eclipse/rse/internal/services/ssh/ISshSessionProvider.java 15 Feb 2007 09:57:05 -0000 1.2 >+++ src/org/eclipse/rse/internal/services/ssh/ISshSessionProvider.java 18 Sep 2007 11:58:45 -0000 >@@ -12,7 +12,7 @@ > * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. > * > * Contributors: >- * {Name} (company) - description of contribution. >+ * Martin Oberhuber (Wind River) - [203500] Support encodings for SSH Sftp paths > *******************************************************************************/ > package org.eclipse.rse.internal.services.ssh; > >@@ -26,4 +26,7 @@ > /* Inform the connectorService that a session has been lost. */ > public void handleSessionLost(); > >+ /* Return the encoding to be used for file and directory names */ >+ public String getControlEncoding(); >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 203500
:
78634
|
78636
|
79249