package org.purl.wf4ever.robundle;

import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;

import org.purl.wf4ever.robundle.fs.BundleFileSystem;

public class Bundle implements AutoCloseable {

    private boolean deleteOnClose;
    private final Path root;

    public Bundle(Path root, boolean deleteOnClose) {
        this.root = root;
        this.setDeleteOnClose(deleteOnClose);
    }

    @Override
    public void close() throws IOException {
        close(isDeleteOnClose());
    }

    protected void close(boolean deleteOnClose) throws IOException {
        getFileSystem().close();
        if (deleteOnClose) {
            Files.deleteIfExists(getSource());
        }
    }

    public FileSystem getFileSystem() {
        return getRoot().getFileSystem();
    }

    public Path getRoot() {
        return root;
    }

    public Path getSource() {
        BundleFileSystem fs = (BundleFileSystem) getFileSystem();
        return fs.getSource();
    }

    public boolean isDeleteOnClose() {
        return deleteOnClose;
    }

    public void setDeleteOnClose(boolean deleteOnClose) {
        this.deleteOnClose = deleteOnClose;
    }

}

@@ -29,16 +29,42 @@
 undle;%0A%0A
+import java.io.Closeable;%0A
 import j
@@ -262,12 +262,8 @@
 nts 
-Auto
 Clos
@@ -630,32 +630,104 @@
 s IOException %7B%0A
+        if (! getFileSystem().isOpen()) %7B%0A            return;%0A        %7D%0A
         getFileS

Make close() idempotent and implement Closable rather than AutoClosable