DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=38686>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=38686





------- Additional Comments From [EMAIL PROTECTED]  2006-02-21 10:29 -------
Hi,

the tmp files are created by the FileReplicator and are deleted during shutdown
of the VFS-Manager.
You may set your own implementation of a FileReplicator (that does a better Job)
via:

((DefaultFileSystemManager) VFS.getManager()).setReplicator(...);

You may gracefully shutdown the default replicator
(VFS.getManager()).getReplicator()) before.

Be sure to do this at application start up!!!

After accessing your tar.gz you should shutdown the implicitly created file
system like so:

((DefaultFileSystemManager)
VFS.getManger()).closeFileSystem(someFileObjectInYourTarGz.getFilesSystem());

This will release the TarFileSystem instance that holds the reference to the tmp
File object.
As far as I know there´s no event (or something like that) to keep track on file
system shutdowns. So you may use a weak reference to the file object (you
replicated) to cleanup the unused temp file:

1. create a class that extends java.lang.ref.WeakReference:
public class WeakFileRef extends WeakReference {
    private String absPath;
    public WeakFileRef(File file, ReferenceQueue queue) {
        super(file, queue);
        this.absPath = file.getAbsolutePath();
    }
    public String getPath() {
        return this.absPath;
    }
}

2. Do your own FileReplicator implementation. You may copy and slightly modify
org.apache.commons.vfs.impl.DefaultFileReplicator. Attention: don´t use any hard
reference on file objects here - use the WeakFileRef class.

3. In your FileReplicator implementation create a field of type ReferenceQueue
    private ReferenceQueue queue = new ReferenceQueue();

4. Change allocateFile(String):
public File allocateFile(final String baseName) throws FileSystemException
{
    WeakFileRef fileRef = (WeakFileRef) queue.poll(); // poll the refence queue
and delete finalized files
    while (fileRef != null) {
        File toDelete = new File(fileRef.getAbsPath());
        try {
            if (toDelete.exists()) {
                toDelete.delete();
            }
        } catch (IOException) {
            // do some exception handling or throw a FileSystemExeption
        }
        copies.remove(fileRef);
        fileRef = (WeakFileRef) queue.poll();
    }

    // Create a unique-ish file name
    final String basename = createFilename(baseName);
    filecount++;
    final File file = createFile(tempDir, basename);

    // Keep track to delete later
    copies.add(new WeakFileRef(file, queue)); // <- changed

    return file;
}

5. Change the close() method -> ArrayList 'copies' now holds WeakFileRef 
objects!

Notice that the files are not cleaned up immediately - it depends on garbage
collection.

Hope this helps/(works) ;-)

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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

Reply via email to