Please apply this patch to NestedVM to fix the unlink() before close() 
issue on Windows (non-POSIX) filesystems. This patch will also clear up 
the extraneous SQLite3 etilqs_XXXXXXXXXX temp files on Windows, and 
other non-POSIX filesystems.

Thanks.


 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLiteJDBC" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlitejdbc?hl=en
-~----------~----~----~----~------~----~------~--~---

--- src-orig/org/ibex/nestedvm/Runtime.java     2007-01-27 10:41:21.046875000 
-0500
+++ src/org/ibex/nestedvm/Runtime.java  2007-02-04 23:48:04.203125000 -0500
@@ -698,18 +698,18 @@
         return i;
     }
 
-    /** Hook for subclasses to do something when the process closes an FD */
-    void _closedFD(FD fd) {  }
+    /** Hooks for subclasses before and after the process closes an FD */
+    void _preCloseFD(FD fd) {  }
+    void _postCloseFD(FD fd) {  }
 
     /** Closes file descriptor <i>fdn</i> and removes it from the file 
descriptor table */
     public final boolean closeFD(int fdn) {
         if(state == EXITED || state == EXECED) throw new 
IllegalStateException("closeFD called in inappropriate state");
         if(fdn < 0 || fdn >= OPEN_MAX) return false;
         if(fds[fdn] == null) return false;
-
-        _closedFD(fds[fdn]);
-
+        _preCloseFD(fds[fdn]);
         fds[fdn].close();
+        _postCloseFD(fds[fdn]);
         fds[fdn] = null;        
         return true;
     }
@@ -1209,6 +1209,14 @@
     /** File Descriptor class */
     public static abstract class FD {
         private int refCount = 1;
+        private String normalizedPath = null;
+        private boolean deleteOnClose = false;
+
+        public void setNormalizedPath(String path) { normalizedPath = path; }
+        public String getNormalizedPath() { return normalizedPath; }
+
+        public void markDeleteOnClose() { deleteOnClose = true; }
+        public boolean isMarkedForDeleteOnClose() { return deleteOnClose; }
         
         /** Read some bytes. Should return the number of bytes read, 0 on EOF, 
or throw an IOException on error */
         public int read(byte[] a, int off, int length) throws ErrnoException { 
throw new ErrnoException(EBADFD); }
--- src-orig/org/ibex/nestedvm/UnixRuntime.java 2006-12-13 16:10:17.000000000 
-0500
+++ src/org/ibex/nestedvm/UnixRuntime.java      2007-02-05 00:32:42.484375000 
-0500
@@ -164,7 +164,10 @@
     }
     
     FD _open(String path, int flags, int mode) throws ErrnoException {
-        return gs.open(this,normalizePath(path),flags,mode);
+        path = normalizePath(path);
+        FD fd = gs.open(this,path,flags,mode);
+        if (fd != null && path != null) fd.setNormalizedPath(path);
+        return fd;
     }
     
     private int sys_getppid() {
@@ -703,7 +706,7 @@
         return n;
     }
 
-    void _closedFD(FD fd) {
+    void _preCloseFD(FD fd) {
         // release all fcntl locks on this file
         Seekable s = fd.seekable();
         if (s == null) return;
@@ -720,6 +723,13 @@
         } catch (IOException e) { throw new RuntimeException(e); }
     }
 
+    void _postCloseFD(FD fd) {
+        if (fd.isMarkedForDeleteOnClose()) {
+            try { gs.unlink(this, fd.getNormalizedPath()); }
+            catch (Throwable t) {}
+        }
+    }
+
     /** Implements the F_GETLK and F_SETLK cases of fcntl syscall.
      *  If l_start = 0 and l_len = 0 the lock refers to the entire file.
      *  Uses GlobalState to ensure locking across processes in the same JVM.
@@ -1617,7 +1627,21 @@
             File f = hostFile(path);
             if(r.sm != null && !r.sm.allowUnlink(f)) throw new 
ErrnoException(EPERM);
             if(!f.exists()) throw new ErrnoException(ENOENT);
-            if(!f.delete()) throw new ErrnoException(EPERM);
+            if(!f.delete()) {
+                // Can't delete file immediately, so mark for
+                // delete on close all matching FDs
+                boolean marked = false;
+                for(int i=0;i<OPEN_MAX;i++) {
+                    if(r.fds[i] != null) {
+                        String fdpath = r.fds[i].getNormalizedPath();
+                        if(fdpath != null && fdpath.equals(path)) {
+                            r.fds[i].markDeleteOnClose();
+                            marked = true;
+                        }
+                    }
+                }
+                if(!marked) throw new ErrnoException(EPERM);
+            }
         }
         
         public FStat stat(UnixRuntime r, String path) throws ErrnoException {

Reply via email to