[
https://issues.jboss.org/browse/JBIDE-10232?page=com.atlassian.jira.plugi...
]
Rob Stryker commented on JBIDE-10232:
-------------------------------------
SafeRename is only called by moveTempFile. moveTempFile begins on line 235. It first
checks if the destination file exists. If it does, it attempts to delete it. If the
deletion fails, it attempts to copy over it. If that fails, it logs an error and halts the
publish attempt.
Assuming not all of the above failed, it will end this batch of code where the destination
no longer exists. It *then* calls safeRename.
I believe it is almost 100% guaranteed that at the time of renameTo, the destination file
does not exist. Two attempts were already made to delete it, and if those failed, an
attempt to copy over it. The only thing I can see is that if it reaches the worst case
(copy over), we do not return from the method early. THis may allow the code to slip into
the renameTo method anyway, as there is no 'else' statement there. At this point,
the tempFile has already been deleted by the finally clause, and so could not possibly be
renameTo'd even if it wanted to be.
Making a commit to return early if the copy over completes successfully. Hope it works :D
exploded deploy does not work on windows because of use of
File#renameTo
------------------------------------------------------------------------
Key: JBIDE-10232
URL:
https://issues.jboss.org/browse/JBIDE-10232
Project: Tools (JBoss Tools)
Issue Type: Bug
Components: JBossAS/Servers
Environment: JBossAS Tools: Version: 2.3.0.v20111104-1515-H45-M4
Java version: 1.5.0_22, vendor: Sun Microsystems Inc.
Java home: C:\devtools\java\jdk1.5.0_22\jre
Default locale: en_CA, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family:
"windows"
Reporter: Jim Sellers
Assignee: Rob Stryker
Fix For: 3.3.0.M5
Setup: in a project on windows with an ear / war / jar in an exploded format and having
started the server in debug mode. If you make any changes to a file in the jar, the jar
will be rebuilt and try to be deployed. This seems to work but it pops up an error dialog
box *every time*. The error message looks like the following:
{code}
Error renaming
C:\devtools\jboss\jboss-4.2.3.GA\server\default\tmp\jbosstoolsTemp\tmp2587902707203199490.jar
to
C:\devtools\jboss\jboss-4.2.3.GA\server\default\deploy\MyExampleEAR.ear\MyExampleWAR.war\WEB-INF\lib\MyDependantJar-2.3-SNAPSHOT.jar.
This may be caused by your server's temporary deploy directory being on a different
filesystem than the final destination.
You may adjust these settings in the server editor.
{code}
For the method
org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil#safeRename(File,File,int) it
calls File#renameTo(File) for moving the file from the temp directory to WEB-INF/lib.
From the javadocs for renameTo it says that this might not work if the file in the
destination already exists.
Possible fixes:
# before calling the rename, try to delete on the destination file ( to.delete() )
# org.apache.commons.io.FileUtils#moveFile(File,File) tries to call the renameTo and if
that fails it falls back to coping the file to the destination.
{code:JAVA|title=Sample Unit test}
/* This test needs to be run on windows. */
@Test
public void testCopyForWindows() throws IOException {
File from = File.createTempFile("source", ".txt");
File to = File.createTempFile("target", ".txt");
File[] files = {from, to};
for (File file : files) {
// set for cleanup
file.deleteOnExit();
assertTrue("file should exist" + file.getAbsolutePath(),
file.exists());
assertTrue("file should be writable" + file.getAbsolutePath(),
file.canWrite());
}
// if safeRename was not private!
assertTrue("should have been able to rename the file", safeRename(from,
to, 10));
}
{code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira