Bug 47626 - File of directory which referred by symbolic link was deleted.
Summary: File of directory which referred by symbolic link was deleted.
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.20
Hardware: All Linux
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-03 01:17 UTC by Ken Tatsushita
Modified: 2009-11-22 14:20 UTC (History)
0 users



Attachments
add new patch (1.08 KB, patch)
2009-08-03 02:18 UTC, Ken Tatsushita
Details | Diff
LocalStrings patch (722 bytes, patch)
2009-08-03 02:34 UTC, Ken Tatsushita
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ken Tatsushita 2009-08-03 01:17:43 UTC
Deploy war.
Make symbolic link in the generated directory.
Symbolic link refer to the directory.
Undeploy war. 
As a result, file of directory which referred by symbolic link was deleted. 

The following are the reproduction methods. 


1.Deploy the sample.war in $TOMCAT_HOME/webapps/

2.Make symbolic link in the generated directory.
  Symbolic link refer to the directory.
[****@**** sample]# ln -s /tmp/sampledir/ sampleln
[****@**** sample]# ls
WEB-INF  sampleln  jsp  
[****@**** sample]# cd sampleln/
[****@**** sampleln]# ls
samplefile.txt

3.Undeploy sample.war.  

4.webapps/sample/ directory is delete. 

5.File of directory which referred by symbolic link was deleted.
[****@**** webapps]# cd /tmp/sampledir/
[****@**** sampledir]# ls 

The file of that directory must not delete!


I made two patches.
This patch added the conditional expression that it was a directory and was not the symbolic link.

Index: java/org/apache/catalina/startup/ExpandWar.java
===================================================================
--- java/org/apache/catalina/startup/ExpandWar.java	(revision 798806)
+++ java/org/apache/catalina/startup/ExpandWar.java	(working copy)
@@ -281,11 +281,17 @@
         }
         for (int i = 0; i < files.length; i++) {
             File file = new File(dir, files[i]);
-            if (file.isDirectory()) {
-                deleteDir(file);
-            } else {
-                file.delete();
-            }
+                try {
+                    if (file.isDirectory()
+                            && file.getCanonicalPath().equals(file.getAbsolutePath())) {
+                        // Directory that is not symbolic link
+                        deleteDir(file);
+                    } else {
+                        file.delete();
+                    }
+                } catch (IOException e) {
+                    log.error(sm.getString("expandWar.canonicalizing",file.getAbsolutePath()), e);
+                }
         }
         return dir.delete();


This patch is LocalStrings

Index: java/org/apache/catalina/startup/LocalStrings.properties
===================================================================
--- java/org/apache/catalina/startup/LocalStrings.properties	(revision 798806)
+++ java/org/apache/catalina/startup/LocalStrings.properties	(working copy)
@@ -59,6 +59,7 @@
 engineConfig.start=EngineConfig: Processing START
 engineConfig.stop=EngineConfig: Processing STOP
 expandWar.copy=Error copying {0} to {1}
+expandWar.canonicalizing=Error delete file or directory [{0}]
 hostConfig.appBase=Application base directory {0} does not exist
 hostConfig.canonicalizing=Error delete redeploy resources from context [{0}]
 hostConfig.cce=Lifecycle event data object {0} is not a Host




Best regards
Comment 1 Ken Tatsushita 2009-08-03 02:18:39 UTC
Created attachment 24085 [details]
add new patch

I'm so sorry.My patch is broken.
I provide new patch.
Comment 2 Ken Tatsushita 2009-08-03 02:34:25 UTC
Created attachment 24086 [details]
LocalStrings patch

add new LocalStrings.patch
Comment 3 Tim Funk 2009-11-03 17:11:08 UTC
I am thinking this is WONTFIX. If a user starts generating symlinks AND relying on autodeploy - bad things will eventually happen.
Comment 4 Mark Thomas 2009-11-22 14:19:00 UTC
Agree with Tim.
Comment 5 Mark Thomas 2009-11-22 14:20:14 UTC
Note that Tomcat 7 includes alias support that provides a safe way of doing this sort of thing.