Hi,

I've got a pretty vanilla Tomcat 5.5.9 install.  It seems like I can't
delete files within my webapp's document root from a servlet.

I have written a trivial servlet to isolate the problem from my app.
All it does is try to delete two files, one is outside the document
root, one is inside.  The external file is deleted, the internal one is
not.

I never create a stream for the internal file, so there shouldn't be
anything with a lock on it.  Tomcat has never served it.  I have tried
the System.gc() hack, it doesn't help.

I encountered these results on Win XP Home.  On Linux (Suse 9.1) the
code works perfectly.

The files are created with this command (in Cygwin), immediately before
starting Tomcat:

echo "I Am A Monkey" >> c:/test.txt; echo "I Am A Monkey Too" >>
c:/java/tomcat559/webapps/jim/ifs/test.txt

Here's the code to the servlet:

    protected void doGet(HttpServletRequest arg0, HttpServletResponse
arg1) throws ServletException, IOException {
        final String _external = "C:\\test.txt";
        final String _internal =
"C:\\java\\tomcat559\\webapps\\jim\\ifs\\test.txt";
        File extFile = new File( _external );
        File intFile = new File( _internal );
        tryDelete( extFile );
        tryDelete( intFile );
    }
    
    private void tryDelete( File file ) {
        System.out.println( "Got file at " + file.getPath() + " (" +
file.length() + " bytes)" );
        System.out.println( "file.exists() == " + file.exists() );
        System.out.println( "file.canWrite() == " + file.canWrite() );
        System.out.println( "file.delete() == " + file.delete() );   
    }

Here's the output:

Got file at C:\test.txt (14 bytes)
file.exists() == true
file.canWrite() == true
file.delete() == true
Got file at C:\java\tomcat559\webapps\jim\ifs\test.txt (36 bytes)
file.exists() == true
file.canWrite() == true
file.delete() == false

Sorry if this is in a spec somewhere, or has already been discussed.  I
took a quick look through the archives, couldn't find anything.

Any help appreciated.

Russ


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to