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

[194293] Xuan's patch for Saving file second time in an Archive Errors

This commit is contained in:
David McKnight 2007-07-12 20:55:52 +00:00
parent 9b746334ea
commit 54645d9950
3 changed files with 72 additions and 11 deletions

View file

@ -13,6 +13,7 @@
*
* Contributors:
* {Name} (company) - description of contribution.
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -367,8 +368,23 @@ public class ArchiveHandlerManager
String newPath = fullVirtualName;
if (j != -1)
{
realPart = fullVirtualName.substring(0, j) + VIRTUAL_SEPARATOR;
newPath = fullVirtualName.substring(j + VIRTUAL_SEPARATOR.length());
try
{
realPart = fullVirtualName.substring(0, j) + VIRTUAL_SEPARATOR;
if (j + VIRTUAL_SEPARATOR.length() < fullVirtualName.length())
{
newPath = fullVirtualName.substring(j + VIRTUAL_SEPARATOR.length());
}
else
{
//This is the special case where fullVirtualName ends with VIRTUAL_SEPARATOR
newPath = ""; //$NON-NLS-1$
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
// use only forward slash separator
newPath = newPath.replace('\\', '/');

View file

@ -13,6 +13,7 @@
*
* Contributors:
* {Name} (company) - description of contribution.
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -1013,8 +1014,9 @@ public class SystemTarHandler implements ISystemArchiveHandler {
if (!file.isDirectory()) {
// if it exists, call replace
if (exists(virtualPath + "/" + name)) { //$NON-NLS-1$
return replace(virtualPath + "/" + name, file, name); //$NON-NLS-1$
String fullVirtualName = getFullVirtualName(virtualPath, name);
if (exists(fullVirtualName)) {
return replace(fullVirtualName, file, name);
}
else {
File[] files = new File[1];
@ -1099,8 +1101,9 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// if the entry already exists, then we should do a replace
// TODO (KM): should we simply replace and return?
// I think we should check each entry and replace or create for each one
if (exists(virtualPath + "/" + names[i])) { //$NON-NLS-1$
return replace(virtualPath + "/" + names[i], files[i], names[i]); //$NON-NLS-1$
String fullVirtualName = getFullVirtualName(virtualPath, names[i]);
if (exists(fullVirtualName)) {
return replace(fullVirtualName, files[i], names[i]);
}
}
@ -2253,4 +2256,24 @@ public class SystemTarHandler implements ISystemArchiveHandler {
// TODO Auto-generated method stub
return false;
}
/**
* Construct the full virtual name of a virtual file from its virtual path and name.
* @param virtualPath the virtual path of this virtual file
* @param name the name of this virtual file
* @return the full virtual name of this virtual file
*/
private static String getFullVirtualName(String virtualPath, String name)
{
String fullVirtualName = null;
if (virtualPath == null || virtualPath.length() == 0)
{
fullVirtualName = name;
}
else
{
fullVirtualName = virtualPath + "/" + name; //$NON-NLS-1$
}
return fullVirtualName;
}
}

View file

@ -14,6 +14,7 @@
* Contributors:
* {Name} (company) - description of contribution.
* Xuan Chen (IBM) - [192741] [Archives] Move a folder from within an Archive doesn't work if > 1 level deep
* Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors
*******************************************************************************/
package org.eclipse.rse.services.clientserver.archiveutils;
@ -907,10 +908,11 @@ public class SystemZipHandler implements ISystemArchiveHandler
for (int i = 0; i < numFiles; i++)
{
if (!files[i].exists() || !files[i].canRead()) return false;
if (exists(virtualPath + "/" + names[i])) //$NON-NLS-1$
String fullVirtualName = getFullVirtualName(virtualPath, names[i]);
if (exists(fullVirtualName))
{
// sorry, wrong method buddy
return replace(virtualPath + "/" + names[i], files[i], names[i]); //$NON-NLS-1$
return replace(fullVirtualName, files[i], names[i]);
}
}
File outputTempFile;
@ -2184,10 +2186,10 @@ public class SystemZipHandler implements ISystemArchiveHandler
virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath);
if (!file.isDirectory())
{
if (exists(virtualPath + "/" + name)) //$NON-NLS-1$
String fullVirtualName = getFullVirtualName(virtualPath, name);
if (exists(fullVirtualName))
{
// wrong method
return replace(virtualPath + "/" + name, file, name); //$NON-NLS-1$
return replace(fullVirtualName, file, name);
}
else
{
@ -2237,4 +2239,24 @@ public class SystemZipHandler implements ISystemArchiveHandler
return add(sources, virtualPath, newNames, sourceEncodings, targetEncodings, isTexts);
}
}
/**
* Construct the full virtual name of a virtual file from its virtual path and name.
* @param virtualPath the virtual path of this virtual file
* @param name the name of this virtual file
* @return the full virtual name of this virtual file
*/
private static String getFullVirtualName(String virtualPath, String name)
{
String fullVirtualName = null;
if (virtualPath == null || virtualPath.length() == 0)
{
fullVirtualName = name;
}
else
{
fullVirtualName = virtualPath + "/" + name; //$NON-NLS-1$
}
return fullVirtualName;
}
}