author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 28 Sep 2011 20:07:49 +0100 | |
branch | jv |
changeset 17865 | 598963c6ff8e |
parent 17846 | 24edc476ac18 |
child 17869 | 9610c6c94e71 |
permissions | -rw-r--r-- |
10847 | 1 |
" |
2 |
COPYRIGHT (c) 2007 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
10761 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
Filename subclass:#AutoDeletedFilename |
|
15 |
instanceVariableNames:'' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'System-Support' |
|
19 |
! |
|
20 |
||
21 |
!AutoDeletedFilename class methodsFor:'documentation'! |
|
22 |
||
10847 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 2007 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
10761 | 37 |
documentation |
38 |
" |
|
39 |
Used with temporary files - these will automatically delete themself, |
|
40 |
when no longer referenced. |
|
41 |
See -> Filename asAutoDeletedFilename |
|
42 |
" |
|
43 |
! |
|
44 |
||
45 |
examples |
|
46 |
" |
|
47 |
the following file will be automatically deleted after some time: |
|
10931
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
48 |
[exBegin] |
10761 | 49 |
|f p| |
50 |
||
51 |
f := Filename newTemporary. |
|
52 |
f writeStream |
|
53 |
nextPutLine:'hello'; |
|
54 |
close. |
|
55 |
p := f pathName. |
|
56 |
Transcript showCR:p. |
|
57 |
f := f asAutoDeletedFilename. |
|
58 |
self assert:(p asFilename exists). |
|
59 |
ObjectMemory collectGarbage. |
|
60 |
Delay waitForSeconds:2. |
|
61 |
self assert:(p asFilename exists). |
|
62 |
f := nil. |
|
63 |
ObjectMemory collectGarbage. |
|
64 |
Delay waitForSeconds:2. |
|
65 |
self assert:(p asFilename exists not). |
|
10931
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
66 |
[exEnd] |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
67 |
|
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
68 |
|
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
69 |
you can also delete it manually: |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
70 |
[exBegin] |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
71 |
|f p| |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
72 |
|
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
73 |
f := Filename newTemporary. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
74 |
f writeStream |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
75 |
nextPutLine:'hello'; |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
76 |
close. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
77 |
p := f pathName. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
78 |
Transcript showCR:p. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
79 |
f := f asAutoDeletedFilename. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
80 |
self assert:(p asFilename exists). |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
81 |
ObjectMemory collectGarbage. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
82 |
Delay waitForSeconds:2. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
83 |
self assert:(p asFilename exists). |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
84 |
f remove. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
85 |
f := nil. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
86 |
ObjectMemory collectGarbage. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
87 |
Delay waitForSeconds:2. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
88 |
self assert:(p asFilename exists not). |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
89 |
[exEnd] |
10761 | 90 |
" |
91 |
! ! |
|
92 |
||
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
93 |
!AutoDeletedFilename class methodsFor:'queries'! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
94 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
95 |
isAbstract |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
96 |
^ true |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
97 |
! ! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
98 |
|
10761 | 99 |
!AutoDeletedFilename methodsFor:'accessing'! |
100 |
||
101 |
finalize |
|
10931
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
102 |
"/ Transcript showCR:'AutoDeletedFilename: deleting ', self pathName. |
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
103 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
104 |
|linkInfo| |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
105 |
|
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
106 |
linkInfo := self linkInfo. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
107 |
linkInfo notNil ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
108 |
linkInfo isDirectory ifTrue:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
109 |
super recursiveRemove |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
110 |
] ifFalse:[ |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
111 |
super removeFile. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
112 |
]. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
113 |
]. |
10761 | 114 |
! |
115 |
||
116 |
setName:aString |
|
117 |
super setName:aString. |
|
118 |
self registerForFinalization |
|
119 |
! ! |
|
120 |
||
10931
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
121 |
!AutoDeletedFilename methodsFor:'removing'! |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
122 |
|
17728
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
123 |
recursiveRemove |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
124 |
super recursiveRemove. |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
125 |
self unregisterForFinalization |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
126 |
! |
bbc5fa73dfab
Merged with trunk r10466
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
127 |
|
10931
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
128 |
remove |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
129 |
super remove. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
130 |
self unregisterForFinalization |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
131 |
! |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
132 |
|
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
133 |
removeDirectory |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
134 |
super removeDirectory. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
135 |
self unregisterForFinalization |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
136 |
! |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
137 |
|
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
138 |
removeFile |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
139 |
super removeFile. |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
140 |
self unregisterForFinalization |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
141 |
! ! |
54107ed355be
unregister from finalizatioin when deleting explicitly
Stefan Vogel <sv@exept.de>
parents:
10847
diff
changeset
|
142 |
|
10761 | 143 |
!AutoDeletedFilename class methodsFor:'documentation'! |
144 |
||
145 |
version |
|
17865 | 146 |
^ '$Id: AutoDeletedFilename.st 10695 2011-09-28 19:07:49Z vranyj1 $' |
147 |
! |
|
148 |
||
149 |
version_SVN |
|
150 |
^ '$Id: AutoDeletedFilename.st 10695 2011-09-28 19:07:49Z vranyj1 $' |
|
17846 | 151 |
! ! |