tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Tomcat 5.5.17 - allowLinking property - symbolic links
Date Wed, 23 Dec 2009 15:49:14 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mark,

On 12/22/2009 4:33 AM, Mark Thomas wrote:
> On 22/12/2009 08:58, Vishwa. K wrote:
>> thanks Mark,
>>    But I was wondering why Tomcat did not remove the complete directory itself.(softlink
target directory). It removed only the nested files in it during undeployment of the application.
> 
> No idea. Permissions maybe? If that isn't it you'd have to look at the
> source code to find an explanation.

I'm guessing that something like this happens:

File layout:
webapps/symlink -> /foo/bar
/foo/bar/dir_a
/foo/bar/dir_b
/foo/bar/file_a

Tomcat tries to delete webapps/symlink recursively. The filesystem (or
maybe java.io.File) descends into webapps/symlink which points to
/foo/bar and collects the files in there (dir_a, dir_b, file_a) and
proceeds to delete them recursively. Once dir_a, dir_b, and file_a are
deleted, the recursion jumps back to the parent (which is
webapps/symlink, NOT /foo/bar) and deletes that.

Thus, the link is deleted but not the target directory.

You can confirm this behavior by running these commands:

mkdir -p foo/bar/dir_a
touch foo/bar/dir_a/file_a
mkdir -p foo/bar/dir_b
touch foo/bar/dir_b/file_a
touch foo/bar/file_a
ln -s foo/bar symlink

And then running this program with "symlink" as the first command-line
argument:

import java.io.File;

public class Rm
{
    public static void main(String[] args)
    {
        File file = new File(args[0]);

        delete(file);
    }

    public static boolean delete(File file)
    {
        boolean success = true;

        if(file.isDirectory())
        {
            File[] children = file.listFiles();

            for(int i=0; i<children.length; ++i)
                success &= delete(children[i]);

            success &= file.delete();
        }

        return success & file.delete();
    }
}

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksyO/oACgkQ9CaO5/Lv0PArFwCgijzHTUv0yaPn4kIBt+MPRkxt
YUUAniKGZgLGWdKyn6tn4eHzYUK4YPmI
=XUd+
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message