Bug 63872 - ContextConfig -> Invalid docBase if the exploded war is a sym-link
Summary: ContextConfig -> Invalid docBase if the exploded war is a sym-link
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.5.47
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-22 06:56 UTC by Kilian Felder
Modified: 2019-11-02 11:57 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kilian Felder 2019-10-22 06:56:38 UTC
The sym-link was working until version 8.5.34, but since 8.5.35 and higher it does not work anymore.

This problem has been reported in Bug #60022 and should be fixed!

Somewhere I found a link where this problem has been discussed again -> http://tomcat.10.x6.nabble.com/Followup2-Changed-behaviour-of-Tomcat-Deployment-Context-Lifecycle-Manager-concerning-symbolic-links-td5083666.html

The cause is located within the ContextConfig class.

diff ContextConfig.java-8.5.34 ContextConfig.java-8.5.35
:
582c586
<             docBase = (new File(appBase, docBase)).getPath();
---
>             docBase = (new File(appBase, docBase)).getCanonicalPath();
Comment 1 Kilian Felder 2019-10-22 09:21:03 UTC
user@testsystem:/path/to/instance/webapps $ ls -l
:
lrwxrwxrwx  ...  myapp.war -> MyApp-4.10.5.0.war.r2308mod-20191017-2100
-rw-rw----  ...  MyApp-4.10.5.0.war.r2308mod-20191017-2100
:
It's not working this way (but was possible until 8.5.34). Here I point with the symlink to the war-file which is in the webapps directory itself, and it must not have the .war suffix because otherwise it would be exploded twice.

user@testsystem:/path/to/instance/webapps $ ls -l
:
lrwxrwxrwx  ...  myapp.war -> ../MyApp-4.10.5.0.war.r2308mod-20191017-2100.war
:
It's working when I place the war-file one level higher and add the .war suffix!

Why do you check for the .war suffix? When it's required to check for the .war suffix you should do this maybe better before the call to getCanonicalPath().
Comment 2 Steve Sanders 2019-10-22 21:58:41 UTC
(In reply to Kilian Felder from comment #1)
> user@testsystem:/path/to/instance/webapps $ ls -l
> :
> lrwxrwxrwx  ...  myapp.war -> MyApp-4.10.5.0.war.r2308mod-20191017-2100
> -rw-rw----  ...  MyApp-4.10.5.0.war.r2308mod-20191017-2100
> :
> It's not working this way (but was possible until 8.5.34). Here I point with
> the symlink to the war-file which is in the webapps directory itself, and it
> must not have the .war suffix because otherwise it would be exploded twice.
> 
> user@testsystem:/path/to/instance/webapps $ ls -l
> :
> lrwxrwxrwx  ...  myapp.war ->
> ../MyApp-4.10.5.0.war.r2308mod-20191017-2100.war
> :
> It's working when I place the war-file one level higher and add the .war
> suffix!
> 
> Why do you check for the .war suffix? When it's required to check for the
> .war suffix you should do this maybe better before the call to
> getCanonicalPath().

Looks like this got added in to ensure consistency of behavior according to the changelog. If I'm not mistaken though, the .war file extension has been requirement for very long time. It feels to me (a user not a contributor) that you were sort of abusing a bug to deploy your application this way in the past.

I'm assuming your aim here is to deploy your application with a different context root than what the actual file name is, so you use a symlink to give it the context you want. If thats correct - why not use META-INF/context.xml to define the context you want here?
Comment 3 Steve Sanders 2019-10-23 01:23:31 UTC
(In reply to Steve Sanders from comment #2)
> (In reply to Kilian Felder from comment #1)
> > user@testsystem:/path/to/instance/webapps $ ls -l
> > :
> > lrwxrwxrwx  ...  myapp.war -> MyApp-4.10.5.0.war.r2308mod-20191017-2100
> > -rw-rw----  ...  MyApp-4.10.5.0.war.r2308mod-20191017-2100
> > :
> > It's not working this way (but was possible until 8.5.34). Here I point with
> > the symlink to the war-file which is in the webapps directory itself, and it
> > must not have the .war suffix because otherwise it would be exploded twice.
> > 
> > user@testsystem:/path/to/instance/webapps $ ls -l
> > :
> > lrwxrwxrwx  ...  myapp.war ->
> > ../MyApp-4.10.5.0.war.r2308mod-20191017-2100.war
> > :
> > It's working when I place the war-file one level higher and add the .war
> > suffix!
> > 
> > Why do you check for the .war suffix? When it's required to check for the
> > .war suffix you should do this maybe better before the call to
> > getCanonicalPath().
> 
> Looks like this got added in to ensure consistency of behavior according to
> the changelog. If I'm not mistaken though, the .war file extension has been
> requirement for very long time. It feels to me (a user not a contributor)
> that you were sort of abusing a bug to deploy your application this way in
> the past.
> 
> I'm assuming your aim here is to deploy your application with a different
> context root than what the actual file name is, so you use a symlink to give
> it the context you want. If thats correct - why not use META-INF/context.xml
> to define the context you want here?

Dug a bit deeper here - and my feelings on the use case aside - it is valid. It also appears to have been fixed in 9.0.20. I'm uncertain if there are plans to backport it to 8.5.X or not. But looking at the code, I THINK its possible to do.
Comment 4 Mark Thomas 2019-11-02 11:57:37 UTC
Thanks for the report.

Fixed in 8.5.x for 8.5.48 onwards.