Hi,

With commons-vfs RC6, I experience sometimes the following exception :
Could not write to "file:///tmp/test/file3.txt" because it is read-only.

I found the cause of this exception, this happens when :
1. a file (file1.txt) is copied to a directory (/tmp/test/) containing the destination file (file3.txt) 2. another process (inside or outside the jvm) delete this directory (/tmp/test) and recreate it. 3. another file (file2.txt) is copied to the same directory (/tmp/test) with the same file name (file3.txt)

I've attached a small junit test showing this exception.
It seems that the object File pointing to file3.txt is maintained in LocalFile between step 1 and 3 but unfortunatelly at step3, this file pointer is no more valid.

I'm using  Sun JDK 1.4.2_10 on Linux Fedora Core 4.

-eric
/*
 * NewEmptyJUnitTest.java
 * JUnit based test
 *
 * Created on December 7, 2005, 5:00 PM
 */
package org.apache.commons.vfs.util;

import junit.framework.*;

import org.apache.commons.vfs.*;

import java.io.File;


/**
 * DOCUMENT ME!
 *
 * @author ehartmann
 */
public class FileUtilTest
    extends TestCase {
    //~ Constructors ...................................................................................................

    /**
     * Creates a new FileUtilTest object.
     *
     * @param testName DOCUMENT ME!
     */
    public FileUtilTest(String testName) {
        super(testName);
    }

    //~ Methods ........................................................................................................

    /**
     * DOCUMENT ME!
     *
     * @throws Exception DOCUMENT ME!
     */
    protected void setUp()
        throws Exception {
    }

    /**
     * DOCUMENT ME!
     *
     * @throws Exception DOCUMENT ME!
     */
    protected void tearDown()
        throws Exception {
    }

    /**
     * DOCUMENT ME!
     *
     * @throws Exception DOCUMENT ME!
     */
    public void testCopy()
        throws Exception {
        FileSystemManager fsManager = VFS.getManager();
        FileObject        file1 = fsManager.resolveFile("/tmp/file1.txt");
        FileObject        file2 = fsManager.resolveFile("/tmp/file2.txt");
        new File("/tmp/test/").mkdirs();

        FileObject file3 = fsManager.resolveFile("/tmp/test/file3.txt");
        FileUtil.copyContent(file1, file3);
        new File("/tmp/test/file3.txt").delete();
        new File("/tmp/test/").delete();
        new File("/tmp/test/").mkdirs();
        file3 = fsManager.resolveFile("/tmp/test/file3.txt");
        FileUtil.copyContent(file2, file3);
    }
}

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

Reply via email to