unregister from finalizatioin when deleting explicitly
authorStefan Vogel <sv@exept.de>
Wed, 02 Apr 2008 17:48:53 +0200
changeset 10931 54107ed355be
parent 10930 95015f0d599e
child 10932 c9148f19b2ea
unregister from finalizatioin when deleting explicitly
AutoDeletedFilename.st
--- a/AutoDeletedFilename.st	Wed Apr 02 17:47:11 2008 +0200
+++ b/AutoDeletedFilename.st	Wed Apr 02 17:48:53 2008 +0200
@@ -45,7 +45,7 @@
 examples
 "
     the following file will be automatically deleted after some time:
-
+                                                    [exBegin]
     |f p|
 
     f := Filename newTemporary.
@@ -63,14 +63,38 @@
     ObjectMemory collectGarbage.
     Delay waitForSeconds:2.
     self assert:(p asFilename exists not).
+                                                    [exEnd]
+
+
+    you can also delete it manually:
+                                                    [exBegin]
+    |f p|
+
+    f := Filename newTemporary.
+    f writeStream
+        nextPutLine:'hello';
+        close.
+    p := f pathName.
+    Transcript showCR:p.
+    f := f asAutoDeletedFilename.
+    self assert:(p asFilename exists).
+    ObjectMemory collectGarbage.
+    Delay waitForSeconds:2.
+    self assert:(p asFilename exists).
+    f remove.
+    f := nil.
+    ObjectMemory collectGarbage.
+    Delay waitForSeconds:2.
+    self assert:(p asFilename exists not).
+                                                    [exEnd]
 "
 ! !
 
 !AutoDeletedFilename methodsFor:'accessing'!
 
 finalize
-    Transcript showCR:'deleting ',self pathName.
-    self delete
+"/    Transcript showCR:'AutoDeletedFilename: deleting ', self pathName.
+    super remove
 !
 
 setName:aString
@@ -78,8 +102,25 @@
     self registerForFinalization    
 ! !
 
+!AutoDeletedFilename methodsFor:'removing'!
+
+remove
+    super remove.
+    self unregisterForFinalization
+!
+
+removeDirectory
+    super removeDirectory.
+    self unregisterForFinalization
+!
+
+removeFile
+    super removeFile.
+    self unregisterForFinalization
+! !
+
 !AutoDeletedFilename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AutoDeletedFilename.st,v 1.2 2008-01-22 22:31:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AutoDeletedFilename.st,v 1.3 2008-04-02 15:48:53 stefan Exp $'
 ! !