You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Eric Hartmann <eh...@sharedvalue.com> on 2005/12/07 17:52:18 UTC
[VFS] Exception while copying FileObject
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
Re: [VFS] Exception while copying FileObject
Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi Eric!
> With commons-vfs RC6, I experience sometimes the following exception :
> Could not write to "file:///tmp/test/file3.txt" because it is read-only.
This again has something to do with the internal vfs cache.
> 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");
>
file3.close();
> FileUtil.copyContent(file2, file3);
>
This will force vfs to refresh its internal states and then it works.
PS: instead of FileUtils you might use
file3.copyFrom(file2, Selectors.SELECT_SELF);
In your case it will do the same, but that way you can also copy
directroies or apply a file filter ...
---
Mario
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org