|
Class: AutoDeletedFilename
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
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
change & update
-
update: anAspect with: aParameter from: changedObject
-
when Smalltalk exits, remove all auto deleted files
initialization
-
initialize
-
inform me when smalltalk exits
instance creation
-
named: aString
-
return a filename for a directory named aString.
This is the same as 'aString asFilename'.
accessing
-
concreteFilename: aFilename
-
Modified (format): / 06-02-2019 / 11:45:44 / Stefan Vogel
-
keep
-
do not delete the file on finalization
-
setName: aString
-
(comment from inherited method)
set the filename
-
species
-
filenames derived from me should not be autodeleted themself
converting
-
asAutoDeletedFilename
-
that's what I am
copying
-
shallowCopy
-
when copying, return a real filename
(to avoid mutiple removals)
delegated to concrete filename
-
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.
-
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.
-
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
-
isDirectory
-
(comment from inherited method)
return true, if the receiver represents an existing,
readable directories pathname.
Symbolic links pointing to a directory answer true.
-
isExecutableProgram
-
(comment from inherited method)
return true, if such a file exists and is an executable program.
(i.e. for directories, false is returned.)
-
isExplicitRelative
-
(comment from inherited method)
return true, if this name is an explicit relative name
(i.e. starts with './' or '../', to avoid path-prepending)
-
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.
-
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.
-
isRootDirectory
-
(comment from inherited method)
return true, if I represent the root directory
(i.e. I have no parentDir)
-
isVolumeAbsolute
-
(comment from inherited method)
return true, if the receiver represents an absolute pathname
on some disk volume (MSDOS only)
-
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.
-
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.
-
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)
-
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.
-
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.
-
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.
-
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
-
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.
-
setHidden
-
(comment from inherited method)
ignored here
- redefined for windows to set the file's hidden flag
-
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
-
basicFinalize
-
-
executor
-
(comment from inherited method)
Return the object which does the finalization for me.
This interface is also VW & Squeak compatible,
-
finalizationLobby
-
answer the registry used for finalization.
we have our own Lobby.
-
finalize
-
do this in a forked process to avoid blocking
removing
-
recursiveRemove
-
-
remove
-
-
removeDirectory
-
-
removeFile
-
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).
|
|