1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-04 15:45:25 +02:00

fix for local copies when there are spaces in path (on linux)

This commit is contained in:
David McKnight 2006-06-30 15:39:22 +00:00
parent de3af0763d
commit d18b434d25

View file

@ -1029,12 +1029,24 @@ public class LocalFileService extends AbstractFileService implements IFileServic
return copyToArchive(srcFile, new File(tgtParent), tgtName, monitor, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false);
}
// handle special characters in source and target strings
StringBuffer srcBuf = new StringBuffer(src);
StringBuffer tgtBuf = new StringBuffer(target);
handleSpecialChars(srcBuf);
handleSpecialChars(tgtBuf);
src = "\"" + srcBuf.toString() + "\"";
target = "\"" + tgtBuf.toString() + "\"";
/*
// handle imbedded blanks of from or to name...
if (src.indexOf(' ') >= 0)
src = "\"" + src + "\"";
if (target.indexOf(' ') >= 0)
target = "\"" + target + "\"";
if (System.getProperty("os.name").toLowerCase().startsWith("win"))
*/
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("win");
if (isWindows)
{
if (folderCopy)
{
@ -1045,6 +1057,7 @@ public class LocalFileService extends AbstractFileService implements IFileServic
}
else
{
if (folderCopy)
{
command = "cp -r " + src + " " + target;
@ -1057,8 +1070,27 @@ public class LocalFileService extends AbstractFileService implements IFileServic
int rc = -1;
try
{
Process p = Runtime.getRuntime().exec(command);
Process p = null;
Runtime runtime = Runtime.getRuntime();
if (isWindows)
{
String theShell = "cmd /C ";
p = runtime.exec(theShell + command);
}
else
{
String theShell = "sh";
String args[] = new String[3];
args[0] = theShell;
args[1] = "-c";
args[2] = command;
p = runtime.exec(args);
}
//Process p = Runtime.getRuntime().exec(command);
rc = p.waitFor();
System.out.println("exit value = " + rc);
//rc = p.exitValue();
}
catch (Exception e)
@ -1068,6 +1100,39 @@ public class LocalFileService extends AbstractFileService implements IFileServic
return (rc == 0);
}
protected void handleSpecialChars(StringBuffer buf)
{
for (int i = 0; i < buf.length(); i++)
{
char c = buf.charAt(i);
boolean isSpecialChar = isSpecialChar(c);
if (isSpecialChar)
{
buf.insert(i, "\\");
i++;
}
}
}
/**
* Checks whether the given character is a special character in the shell. A special character is
* '$', '`', '"' and '\'.
* @param c the character to check.
* @return <code>true</code> if the character is a special character, <code>false</code> otherwise.
*/
protected boolean isSpecialChar(char c) {
if ((c == '$') || (c == '`') || (c == '"') || (c == '\\') ) {
return true;
}
else {
return false;
}
}
/**
* Copy a file or folder to a new target parent folder, but if
* copying from an archive, extract the file in the encoding specified