Summary: | [Local][Archives] Saving file second time in an Archive Errors | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | [Tools] Target Management | Reporter: | Kevin Doyle <kjdoyle> | ||||||||
Component: | RSE | Assignee: | Xuan Chen <xuanchen> | ||||||||
Status: | CLOSED FIXED | QA Contact: | Martin Oberhuber <mober.at+eclipse> | ||||||||
Severity: | normal | ||||||||||
Priority: | P3 | CC: | dmcknigh, kmunir, xuanchen | ||||||||
Version: | 2.0 | Keywords: | contributed | ||||||||
Target Milestone: | 2.0.1 | ||||||||||
Hardware: | PC | ||||||||||
OS: | Windows XP | ||||||||||
Whiteboard: | |||||||||||
Attachments: |
|
Description
Kevin Doyle
2007-06-25 15:53:43 EDT
I found that it only happens to the files which are the immediate children of the zip file. e.g., myzip.zip/#virtual/aa.txt. If a file exists inside a virtual folder, it works fine. It seems the problem is in the SystemZipHandler#add() method: public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText) { if (!_exists) return false; virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); if (!file.isDirectory()) { if (exists(virtualPath + "/" + name)) //$NON-NLS-1$ { // wrong method return replace(virtualPath + "/" + name, file, name); //$NON-NLS-1$ } else { . . . As you can see, if a virtual path is "", the fullVirtualName of this virtual file passed to replace() method will be something like "/filename.txt", instead of "filename.txt". So we need to handle this special case separately. The change will be something like this: public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText) { if (!_exists) return false; virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); if (!file.isDirectory()) { String fullVirtualName = null; if (virtualPath == null || virtualPath.length() == 0) { fullVirtualName = name; } else { fullVirtualName = virtualPath + "/" + name; //$NON-NLS-1$ } if (exists(fullVirtualName)) { return replace(fullVirtualName, file, name); } else { . . . Xuan can you come up with a patch? Created attachment 73285 [details] Fix for bug 194293 Legal Message: I, Xuan Chen, declare that I developed attached code from scratch, without referencing any 3rd party materials except material licensed under the EPL. I am authorized by my employer, IBM Canada Ltd. to make this contribution under the EPL. *** Bug 187384 has been marked as a duplicate of this bug. *** Please take a look at this patch to see if it is ok. I probably need to change these source for the other archive problem I am going to investigate. Thanks. Xuan, it looks like there is some code that is duplicated a few times in the patch. For example: if (virtualPath == null || virtualPath.length() == 0) { fullVirtualName = names[i]; } else { fullVirtualName = virtualPath + "/" + names[i]; //$NON-NLS-1$ } I would be cleaner if you could create a couple methods to do these things. Created attachment 73679 [details]
Updated according to DaveM's comment.
Legal Message: I, Xuan Chen, declare that I developed attached code from
scratch, without referencing any 3rd party materials except material licensed
under the EPL. I am authorized by my employer, IBM Canada Ltd. to make this
contribution under the EPL.
Since the change is to add a non-private method in ArchiveHandlerManager, which is not an internal class, it is an API change (thanks Kevin for reminding me). I will create one private method each in both SystemZipHandler and SystemTarHandler for now. And will move it to ArchiveHandlerManager later. I will open another bug to track it. Created attachment 73685 [details]
change the method as private methods for Tar and Zip handlers
Legal Message: I, Xuan Chen, declare that I developed attached code from
scratch, without referencing any 3rd party materials except material licensed
under the EPL. I am authorized by my employer, IBM Canada Ltd. to make this
contribution under the EPL.
I've committed the patch. Verified with I20070713-0605. |