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.19 date: 2019/07/15 11:24:14
user: cg
file: AutoDeletedFilename.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
cg - original code
sv - fixed and enhanced

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


Class protocol:

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

initialization
o  initialize
inform me when smalltalk exits

instance creation
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  keep
do not delete the file on finalization

o  setName: aString
(comment from inherited method)
set the filename

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 pathname of the file represented by the receiver,
as a string. This will not include ..'s.
If the path represented by the receiver does NOT represent a valid path,
no compression will be done (for now; this may change).
See also: name

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

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

removing
o  recursiveRemove

o  remove

o  removeDirectory

o  removeFile


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.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 19 Apr 2024 07:41:08 GMT