AutoDeletedFilename.st
branchjv
changeset 18640 358b275dced9
parent 18120 e3a375d5f6a8
parent 18635 4fe209fa4826
child 21292 21faad473411
--- a/AutoDeletedFilename.st	Fri Jul 24 08:09:56 2015 +0100
+++ b/AutoDeletedFilename.st	Sat Jul 25 06:39:11 2015 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2007 by eXept Software AG
               All Rights Reserved
@@ -11,9 +13,11 @@
 "
 "{ Package: 'stx:libbasic' }"
 
+"{ NameSpace: Smalltalk }"
+
 Filename subclass:#AutoDeletedFilename
 	instanceVariableNames:''
-	classVariableNames:''
+	classVariableNames:'Lobby'
 	poolDictionaries:''
 	category:'System-Support'
 !
@@ -90,6 +94,35 @@
 "
 ! !
 
+!AutoDeletedFilename class methodsFor:'initialization'!
+
+initialize
+    Lobby isNil ifTrue:[
+        Lobby := Registry new.
+    ].
+    Smalltalk addDependent:self.    "inform me when smalltalk exits"
+! !
+
+!AutoDeletedFilename class methodsFor:'change and update'!
+
+update:anAspect with:aParameter from:changedObject
+    "when Smalltalk exits, remove all auto deleted files"
+
+    anAspect == #aboutToQuit ifTrue:[
+        |currentFilename|
+        "do it with timeout in case of a non-responding remote file server"
+        ([
+            Lobby do:[:each|
+                currentFilename := each.
+                each basicFinalize
+            ].
+        ] valueWithTimeout:1 minutes) isNil ifTrue:[
+            'AutoDeletedFilename: timed out while removing: ' errorPrint. currentFilename errorPrintCR.
+        ].
+    ].
+    super update:anAspect with:aParameter from:changedObject
+! !
+
 !AutoDeletedFilename methodsFor:'accessing'!
 
 keep
@@ -118,26 +151,37 @@
 
 !AutoDeletedFilename methodsFor:'finalization'!
 
+basicFinalize
+    |linkInfo|
+
+    linkInfo := self linkInfo.
+    linkInfo notNil ifTrue:[
+        linkInfo isDirectory ifTrue:[
+            super recursiveRemove
+        ] ifFalse:[
+            super removeFile.
+        ].
+    ].
+!
+
 executor
     ^ self class basicNew nameString:nameString
 !
 
+finalizationLobby
+    "answer the registry used for finalization.
+     we have our own Lobby."
+
+    ^ Lobby
+!
+
 finalize
-    |linkInfo|
-
     "/ do this in a forked process to avoid blocking
     "/ in case of an autodeleted remote file of a broken connection
     [
         "/ with timeout to avoid waiting forever
         [
-            linkInfo := self linkInfo.
-            linkInfo notNil ifTrue:[
-                linkInfo isDirectory ifTrue:[
-                    super recursiveRemove
-                ] ifFalse:[
-                    super removeFile.
-                ].
-            ].
+            self basicFinalize.
         ] valueWithTimeout:1 minutes.
     ] fork.
 ! !
@@ -175,6 +219,12 @@
 !AutoDeletedFilename class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AutoDeletedFilename.st,v 1.12 2014-06-07 15:08:38 cg Exp $'
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
 ! !
 
+
+AutoDeletedFilename initialize!