eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'AutoDeletedFilename':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: AutoDeletedFilename


Inheritance:

   Object
   |
   +--Filename
      |
      +--AutoDeletedFilename

Package:
stx:libbasic
Category:
System-Support
Version:
rev: 1.36 date: 2024/03/22 10:26:12
user: stefan
file: AutoDeletedFilename.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


Used with temporary files - these will automatically delete themself,
when no longer referenced (i.e. when finalized)

See -> Filename asAutoDeletedFilename

[instance variables:]
    concreteFilename    UnixFilename|PCFilename     the concrete filename that
                                                    implements the OS-specific behavior

copyright

COPYRIGHT (c) 2007 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

change & update
o  removeFailedFiles
try again to remove files which previously failed to remove

o  update: anAspect with: aParameter from: changedObject
when Smalltalk exits, remove all auto deleted files

class initialization
o  initialize
limit the amount of newspace to be used for non-tenurable executors to 2.5%,
but at most 1000

instance creation
o  concreteClass
filenames derived from me should not be autodeleted themself

o  named: aString
return a filename for a directory named aString.
This is the same as 'aString asFilename'.


Instance protocol:

accessing
o  concreteFilename: aFilename
Modified (format): / 06-02-2019 / 11:45:44 / Stefan Vogel

o  creator: aContext
the context chain of the creator (for debugging);
if an error happens when autoDeleting, we'll see who created that file,
and may find why it is still open.

o  creatorWalkback
the context chain of the creator (for debugging);
if an error happens when autoDeleting, we'll see who created that file,
and may find why it is still open.

o  keep
do not delete the file on finalization

o  setName: aString
keep track of where an auto-delete-file was created;

o  species
filenames derived from me should not be autodeleted themself

converting
o  asAutoDeletedFilename
that's what I am

copying
o  shallowCopy
when copying, return a real filename
(to avoid mutiple removals)

delegated to concrete filename
o  directoryName
(comment from inherited method)
return the directory name part of the file/directory as a string.
- that's the name of the directory where the file/dir represented by
the receiver is contained in.
This method does not check if the path is valid.

(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
and '/usr/lib' asFilename directoryName -> /usr').

(this is almost equivalent to #directory, but returns
a string instead of a Filename instance).

See also: #pathName, #directoryPathName and #baseName.
Compatibility note: use #head for ST-80 compatibility.

o  fileType
(comment from inherited method)
this returns a string describing the type of contents of
the file. This is done using the unix 'file' command,
(which usually is configurable by /etc/magic).
On non-unix systems, this may simply return 'file',
not knowning about the contents.
Warning:
Since the returned string differs among systems (and language settings),
it is only useful for user-information;
NOT as a tag to be used by a program.

o  fullAlternativePathName
(comment from inherited method)
some filesystems (aka: windows) have alternative (short) filenames.
Those systems redefine this method to return it.
Otherwise, the same as the regular name is returned here

o  isDirectory
(comment from inherited method)
return true, if the receiver represents an existing,
readable directories pathname.
Symbolic links pointing to a directory answer true.

o  isExecutableProgram
(comment from inherited method)
return true, if such a file exists and is an executable program.
(i.e. for directories, false is returned.)

o  isExplicitRelative
(comment from inherited method)
return true, if this name is an explicit relative name
(i.e. starts with './' or '../', to avoid path-prepending)

o  isHidden
(comment from inherited method)
return true, if the receiver represents a hidden file.
The definitions of hidden files depends on the OS used;
on UNIX, a name starting with a period is considered hidden;
on MSDOS, the file's hidden attribute is also used.
VMS has no concept of hidden files.

o  isImplicit
(comment from inherited method)
return true, if the receiver represents a builtin file.
The definitions of builtin files depends on the OS used;
on UNIX, '.' and '..' are builtin names.

o  isRootDirectory
(comment from inherited method)
return true, if I represent the root directory
(i.e. I have no parentDir)

o  isVolumeAbsolute
(comment from inherited method)
return true, if the receiver represents an absolute pathname
on some disk volume (MSDOS only)

o  localPathName
(comment from inherited method)
return the full pathname of the file represented by the receiver,
but without any volume information.
Only makes a difference on MSDOS & VMS systems.

o  makeLegalFilename
(comment from inherited method)
convert the receiver's name to be a legal filename.
This removes/replaces invalid characters and/or compresses
the name as required by the OS.
The implementation may change in the future to be more
OS specific.

o  osNameForAccess
(comment from inherited method)
internal - return the OS's name for the receiver to
access its fileInfo.
This may be redefined for systems, where a special suffix must be
added in order to access directories (or others) as a file.
(i.e. under VMS, a '.dir' suffix is added to access directories)

o  osNameForDirectory
(comment from inherited method)
internal - return the OS's name for the receiver to
access it as a directory.
Note: this may return an absolute pathName, if there are
place holders in the name.
Otherwise it keeps the name relative or absolute as it is.

o  osNameForDirectoryContents
(comment from inherited method)
internal - return the OS's name for the receiver to
access it as a directory when reading its contents.
Note: this may return an absolute pathName, if there are
place holders in the name.
Otherwise it keeps the name relative or absolute as it is.

o  osNameForFile
(comment from inherited method)
internal - return the OS's name for the receiver to
access it as a file.
Note: this may return an absolute pathName, if there are
place holders in the name.
Otherwise it keeps the name relative or absolute as it is.

o  pathName
(comment from inherited method)
return the full absolute pathname of the file represented by the receiver,
as a string. This will not include ..'s.
Symbolic links in the path will be resolved.

If the file does not exist or is not accessible, a simple compression
(compressing '.' and '..') will be done, but relative names will not be
returned as absolute name.
This is by purpose, so that a relative pathname remains as such when used
in the context of another user or other current-directory.

See also: name

o  renameTo: newName overwrite: overwriteBool
(comment from inherited method)
rename the file to newName. newName must be convertable to a filename.
Raises an exception if not successful.
If newName already exists, it will be replaced by myself.

'overwrite'
if newName exists and overwrite == false, this method will fail (only on windows os).
If overwrite == true, the rename will replace an existing newName target file.

o  setHidden
(comment from inherited method)
ignored here
- redefined for windows to set the file's hidden flag

o  volume
(comment from inherited method)
return the disc volume part of the name or an empty string.
This is only used with MSDOS and VMS filenames
- by default (and on unix), an empty string is returned

finalization
o  basicFinalize

o  executor
(comment from inherited method)
Return the object which does the finalization for me.
This interface is also VW & Squeak compatible,

o  finalizationLobby
answer the registry used for finalization.
we have our own Lobby.

o  finalize
do this in a forked process to avoid blocking

o  registerForFinalization
keep myself in newSpace, so I will be finalized early

o  removeMyself

removing
o  recursiveRemove
(comment from inherited method)
if I represent a regular file, remove it.
Otherwise, remove the directory and all of its subfiles/subdirectories.
Raise an exception if not successful.

o  remove
(comment from inherited method)
remove the file/directory.
Raises an exception if not successful (but not if it did not exist in the first place).
Use #recursiveRemove in order to (recursively) remove non empty directories.

o  removeDirectory
(comment from inherited method)
remove the directory.
No error is raised, if the directory does not exist in the first place.
Raises an exception if not successful (or if it's not a directory).
Use #remove if it is not known if the receiver is a directory or file.
Use #recursiveRemove in order to (recursively) remove non empty directories.

o  removeFile
(comment from inherited method)
remove the file.
No error is raised, if the file does not exist in the first place.
Raises an exception if not successful (or if it's not a file).
Use #remove if it is not known if the receiver is a directory or file.
Use #recursiveRemove in order to (recursively) remove non empty directories.


Examples:


the following file will be automatically deleted after some time:
|f p|

f := AutoDeletedFilename 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 := nil.
ObjectMemory collectGarbage.
Delay waitForSeconds:2.
self assert:(p asFilename exists not).
you can also delete it manually:
|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).


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 06:42:43 GMT