mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 13:05:22 +02:00
[235477][ssh] SftpFileService.createFolder() fails for file named "a?*"
This commit is contained in:
parent
7fd4ac6495
commit
aa2297c58b
1 changed files with 25 additions and 17 deletions
|
@ -30,6 +30,7 @@
|
||||||
* Martin Oberhuber (Wind River) - [190904] Changing read-only attribute throws exception
|
* Martin Oberhuber (Wind River) - [190904] Changing read-only attribute throws exception
|
||||||
* Martin Oberhuber (Wind River) - [218042] Support UNIX permission modification on ssh
|
* Martin Oberhuber (Wind River) - [218042] Support UNIX permission modification on ssh
|
||||||
* Martin Oberhuber (Wind River) - [233651] Make ssh delete throw proper exceptions
|
* Martin Oberhuber (Wind River) - [233651] Make ssh delete throw proper exceptions
|
||||||
|
* Martin Oberhuber (Wind River) - [235477][ssh] SftpFileService.createFolder() fails for file named "a?*"
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.services.ssh.files;
|
package org.eclipse.rse.internal.services.ssh.files;
|
||||||
|
@ -259,9 +260,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
msg += "Please specify a different encoding in host properties."; //$NON-NLS-1$
|
msg += "Please specify a different encoding in host properties."; //$NON-NLS-1$
|
||||||
throw new UnsupportedEncodingException(msg);
|
throw new UnsupportedEncodingException(msg);
|
||||||
}
|
}
|
||||||
//Quote ? and * characters for Jsch
|
return recoded;
|
||||||
//FIXME bug 204705: this does not work properly for commands like ls(), due to a Jsch bug
|
|
||||||
return quoteForJsch(recoded);
|
|
||||||
} catch(UnsupportedEncodingException e) {
|
} catch(UnsupportedEncodingException e) {
|
||||||
|
|
||||||
//SystemMessage msg = new SystemMessage("RSE","F","9999",'E',e.getMessage(),"Please specify a different encoding in host properties."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
//SystemMessage msg = new SystemMessage("RSE","F","9999",'E',e.getMessage(),"Please specify a different encoding in host properties."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||||
|
@ -272,6 +271,14 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String recodeSafeForJsch(String s) throws SystemMessageException {
|
||||||
|
String recoded = recodeSafe(s);
|
||||||
|
// Quote ? and * characters for Jsch
|
||||||
|
// FIXME bug 204705: this does not work properly for commands like ls(),
|
||||||
|
// due to a Jsch bug
|
||||||
|
return quoteForJsch(recoded);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode String (sftp result) with requested user encoding, in case it differs from Platform default encoding.
|
* Decode String (sftp result) with requested user encoding, in case it differs from Platform default encoding.
|
||||||
* @param s String to decode
|
* @param s String to decode
|
||||||
|
@ -308,8 +315,8 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
StringBuffer buf = new StringBuffer(s.length()+8);
|
StringBuffer buf = new StringBuffer(s.length()+8);
|
||||||
for(int i=0; i<s.length(); i++) {
|
for(int i=0; i<s.length(); i++) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
// if(c=='?' || c=='*' || c=='\\') {
|
if (c == '?' || c == '*' || c == '\\') {
|
||||||
if(c=='?' || c=='*') {
|
//if(c=='?' || c=='*') {
|
||||||
buf.append('\\');
|
buf.append('\\');
|
||||||
}
|
}
|
||||||
buf.append(c);
|
buf.append(c);
|
||||||
|
@ -458,7 +465,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
String fullPath = concat(remoteParent, fileName);
|
String fullPath = concat(remoteParent, fileName);
|
||||||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||||
try {
|
try {
|
||||||
attrs = getChannel("SftpFileService.getFile: "+fullPath).stat(recodeSafe(fullPath)); //$NON-NLS-1$
|
attrs = getChannel("SftpFileService.getFile: " + fullPath).stat(recodeSafeForJsch(fullPath)); //$NON-NLS-1$
|
||||||
Activator.trace("SftpFileService.getFile <--"); //$NON-NLS-1$
|
Activator.trace("SftpFileService.getFile <--"); //$NON-NLS-1$
|
||||||
node = makeHostFile(remoteParent, fileName, attrs);
|
node = makeHostFile(remoteParent, fileName, attrs);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -507,7 +514,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||||
boolean haveSubMonitor = false;
|
boolean haveSubMonitor = false;
|
||||||
try {
|
try {
|
||||||
Vector vv=getChannel("SftpFileService.internalFetch: "+parentPath).ls(recodeSafe(parentPath)); //$NON-NLS-1$
|
Vector vv = getChannel("SftpFileService.internalFetch: " + parentPath).ls(recodeSafeForJsch(parentPath)); //$NON-NLS-1$
|
||||||
progressTick(monitor, 40);
|
progressTick(monitor, 40);
|
||||||
if (vv.size()>1 && monitor!=null) {
|
if (vv.size()>1 && monitor!=null) {
|
||||||
monitor = new SubProgressMonitor(monitor, 40);
|
monitor = new SubProgressMonitor(monitor, 40);
|
||||||
|
@ -562,9 +569,10 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
if (attrs.isLink()) {
|
if (attrs.isLink()) {
|
||||||
//check if the link points to a directory
|
//check if the link points to a directory
|
||||||
try {
|
try {
|
||||||
|
String fullPath = concat(parentPath, fileName);
|
||||||
boolean readlinkDone = false;
|
boolean readlinkDone = false;
|
||||||
try {
|
try {
|
||||||
linkTarget=decode(getChannel("makeHostFile.readlink").readlink(recode(concat(parentPath, fileName)))); //$NON-NLS-1$
|
linkTarget = decode(getChannel("makeHostFile.readlink").readlink(recode(fullPath))); //$NON-NLS-1$
|
||||||
readlinkDone = true;
|
readlinkDone = true;
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
//readlink() is only supported on sftpv3 and later servers, and jsch-0.1.29 or higher.
|
//readlink() is only supported on sftpv3 and later servers, and jsch-0.1.29 or higher.
|
||||||
|
@ -574,11 +582,11 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
// * Immediate link target is not available, only the fully resolved link target (might be an advantage too!)
|
// * Immediate link target is not available, only the fully resolved link target (might be an advantage too!)
|
||||||
// * -- but clients can also resolve the path with the
|
// * -- but clients can also resolve the path with the
|
||||||
// * Immediate link target is not available for broken symbolic links
|
// * Immediate link target is not available for broken symbolic links
|
||||||
getChannel("makeHostFile.chdir").cd(recode(concat(parentPath, fileName))); //$NON-NLS-1$
|
getChannel("makeHostFile.chdir").cd(recode(fullPath)); //$NON-NLS-1$
|
||||||
linkTarget=decode(getChannel("makeHostFile.pwd").pwd()); //$NON-NLS-1$
|
linkTarget=decode(getChannel("makeHostFile.pwd").pwd()); //$NON-NLS-1$
|
||||||
canonicalPath=linkTarget;
|
canonicalPath=linkTarget;
|
||||||
}
|
}
|
||||||
if (linkTarget!=null && !linkTarget.equals(concat(parentPath, fileName))) {
|
if (linkTarget != null && !linkTarget.equals(fullPath)) {
|
||||||
if (readlinkDone) {
|
if (readlinkDone) {
|
||||||
//linkTarget may be a relative path name that needs to be resolved for stat() to work properly
|
//linkTarget may be a relative path name that needs to be resolved for stat() to work properly
|
||||||
String curdir=decode(getChannel("makeHostFile.pwd").pwd()); //$NON-NLS-1$
|
String curdir=decode(getChannel("makeHostFile.pwd").pwd()); //$NON-NLS-1$
|
||||||
|
@ -589,7 +597,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
attrsTarget = getChannel("SftpFileService.getFile").stat(recode(linkTarget)); //$NON-NLS-1$
|
attrsTarget = getChannel("SftpFileService.getFile").stat(recode(linkTarget)); //$NON-NLS-1$
|
||||||
if (readlinkDone && attrsTarget.isDir()) {
|
if (readlinkDone && attrsTarget.isDir()) {
|
||||||
//TODO JSch should have realpath() API
|
//TODO JSch should have realpath() API
|
||||||
getChannel("makeHostFile.chdir").cd(recode(concat(parentPath, fileName))); //$NON-NLS-1$
|
getChannel("makeHostFile.chdir").cd(recode(fullPath)); //$NON-NLS-1$
|
||||||
canonicalPath=decode(getChannel("makeHostFile.pwd").pwd()); //$NON-NLS-1$
|
canonicalPath=decode(getChannel("makeHostFile.pwd").pwd()); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -663,7 +671,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
try {
|
try {
|
||||||
SftpProgressMonitor sftpMonitor=new MyProgressMonitor(monitor);
|
SftpProgressMonitor sftpMonitor=new MyProgressMonitor(monitor);
|
||||||
int mode=ChannelSftp.OVERWRITE;
|
int mode=ChannelSftp.OVERWRITE;
|
||||||
dst = recodeSafe(dst);
|
dst = recodeSafeForJsch(dst);
|
||||||
getChannel("SftpFileService.upload "+remoteFile); //check the session is healthy //$NON-NLS-1$
|
getChannel("SftpFileService.upload "+remoteFile); //check the session is healthy //$NON-NLS-1$
|
||||||
channel=(ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
|
channel=(ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
|
||||||
channel.connect();
|
channel.connect();
|
||||||
|
@ -858,7 +866,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
String fullPath = concat(remoteParent, fileName);
|
String fullPath = concat(remoteParent, fileName);
|
||||||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||||
try {
|
try {
|
||||||
String fullPathRecoded = recodeSafe(concat(remoteParent, fileName));
|
String fullPathRecoded = recodeSafeForJsch(concat(remoteParent, fileName));
|
||||||
OutputStream os = getChannel("SftpFileService.createFile").put(fullPathRecoded); //$NON-NLS-1$
|
OutputStream os = getChannel("SftpFileService.createFile").put(fullPathRecoded); //$NON-NLS-1$
|
||||||
os.close();
|
os.close();
|
||||||
SftpATTRS attrs = getChannel("SftpFileService.createFile.stat").stat(fullPathRecoded); //$NON-NLS-1$
|
SftpATTRS attrs = getChannel("SftpFileService.createFile.stat").stat(fullPathRecoded); //$NON-NLS-1$
|
||||||
|
@ -884,7 +892,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
try {
|
try {
|
||||||
String fullPathRecoded = recodeSafe(fullPath);
|
String fullPathRecoded = recodeSafe(fullPath);
|
||||||
getChannel("SftpFileService.createFolder").mkdir(fullPathRecoded); //$NON-NLS-1$
|
getChannel("SftpFileService.createFolder").mkdir(fullPathRecoded); //$NON-NLS-1$
|
||||||
SftpATTRS attrs = getChannel("SftpFileService.createFolder.stat").stat(fullPathRecoded); //$NON-NLS-1$
|
SftpATTRS attrs = getChannel("SftpFileService.createFolder.stat").stat(quoteForJsch(fullPathRecoded)); //$NON-NLS-1$
|
||||||
result = makeHostFile(remoteParent, folderName, attrs);
|
result = makeHostFile(remoteParent, folderName, attrs);
|
||||||
Activator.trace("SftpFileService.createFolder ok"); //$NON-NLS-1$
|
Activator.trace("SftpFileService.createFolder ok"); //$NON-NLS-1$
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -905,7 +913,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
Activator.trace("SftpFileService.delete.waitForLock"); //$NON-NLS-1$
|
Activator.trace("SftpFileService.delete.waitForLock"); //$NON-NLS-1$
|
||||||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||||
try {
|
try {
|
||||||
String fullPathRecoded = recodeSafe(fullPath);
|
String fullPathRecoded = recodeSafeForJsch(fullPath);
|
||||||
SftpATTRS attrs = null;
|
SftpATTRS attrs = null;
|
||||||
try {
|
try {
|
||||||
attrs = getChannel("SftpFileService.delete").lstat(fullPathRecoded); //$NON-NLS-1$
|
attrs = getChannel("SftpFileService.delete").lstat(fullPathRecoded); //$NON-NLS-1$
|
||||||
|
@ -963,7 +971,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
String fullPathNew = concat(remoteParent, newName);
|
String fullPathNew = concat(remoteParent, newName);
|
||||||
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
if (fDirChannelMutex.waitForLock(monitor, fDirChannelTimeout)) {
|
||||||
try {
|
try {
|
||||||
getChannel("SftpFileService.rename").rename(recode(fullPathOld), recodeSafe(fullPathNew)); //$NON-NLS-1$
|
getChannel("SftpFileService.rename").rename(recode(fullPathOld), recodeSafeForJsch(fullPathNew)); //$NON-NLS-1$
|
||||||
Activator.trace("SftpFileService.rename ok"); //$NON-NLS-1$
|
Activator.trace("SftpFileService.rename ok"); //$NON-NLS-1$
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Activator.trace("SftpFileService.rename "+fullPathOld+" -> "+fullPathNew+" failed: "+e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
Activator.trace("SftpFileService.rename "+fullPathOld+" -> "+fullPathNew+" failed: "+e.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||||
|
@ -1223,7 +1231,7 @@ public class SftpFileService extends AbstractFileService implements ISshService,
|
||||||
getChannel("SftpFileService.getOutputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
|
getChannel("SftpFileService.getOutputStream " + remoteFile); //check the session is healthy //$NON-NLS-1$
|
||||||
ChannelSftp channel = (ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
|
ChannelSftp channel = (ChannelSftp)fSessionProvider.getSession().openChannel("sftp"); //$NON-NLS-1$
|
||||||
channel.connect();
|
channel.connect();
|
||||||
stream = new SftpBufferedOutputStream(channel.put(recodeSafe(dst), sftpMonitor, mode), channel);
|
stream = new SftpBufferedOutputStream(channel.put(recodeSafeForJsch(dst), sftpMonitor, mode), channel);
|
||||||
Activator.trace("SftpFileService.getOutputStream " + remoteFile + " ok"); //$NON-NLS-1$ //$NON-NLS-2$
|
Activator.trace("SftpFileService.getOutputStream " + remoteFile + " ok"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue