UnixFilename.st
author Claus Gittinger <cg@exept.de>
Mon, 15 Dec 1997 11:33:38 +0100
changeset 3125 543358373041
parent 2943 89dee83077bd
child 3171 02ef7b6cc664
permissions -rw-r--r--
care for filenames with blanks when invoking 'file' command

"
 COPYRIGHT (c) 1997 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.
"

Filename subclass:#UnixFilename
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'OS-Unix'
!

!UnixFilename class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 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.
"
!

documentation
"
    Filenames in Unix.
"

! !

!UnixFilename class methodsFor:'queries'!

isBadCharacter:aCharacter
    "return true, if aCharacter is unallowed in a filename."

    aCharacter == $/ ifTrue:[^ true].
    ^ super isBadCharacter:aCharacter

    "Created: 8.9.1997 / 00:13:14 / cg"
!

isCaseSensitive
    "return true, if filenames are case sensitive.return true, if filenames are case sensitive."

    ^ true
!

parentDirectoryName
    "return the name used for the parent directory.
     This is '..' for unix and dos-like systems.
     (there may be more in the future."

    ^ '..'
!

separator
    "return the file/directory separator."

     ^ $/

     "
      Filename concreteClass separator  
     "

    "Created: 8.9.1997 / 00:18:14 / cg"
! !

!UnixFilename methodsFor:'file queries'!

fileType
    "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 return an empty string, not knowning
     about the contents.
     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."

    |stream typeString|

    "/ since executing 'file' takes some time, do the most common
    "/ ones are checked first, using the general fileType implementation. 
    "/ (also, the file-command is only available on Unix systems.

    typeString := super fileType.
    typeString ~= 'file' ifTrue:[^ typeString].

    stream := PipeStream readingFrom:('file "' , self pathName , '"').
    stream notNil ifTrue:[
	typeString := stream contents asString.
	stream close.
	typeString := typeString copyFrom:(typeString indexOf:$:) + 1.
	typeString := typeString withoutSeparators
    ].
    ^ typeString

    "
     'Makefile' asFilename fileType 
     '.' asFilename fileType     
     '/dev/null' asFilename fileType        
     'smalltalk.rc' asFilename fileType    
     'bitmaps/SBrowser.xbm' asFilename fileType    
    "

    "Modified: 7.9.1997 / 23:43:03 / cg"
! !

!UnixFilename methodsFor:'queries'!

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

    (nameString startsWith:'./') ifTrue:[
	^ true
    ].
    (nameString startsWith:'../') ifTrue:[
	^ true
    ].
    ^ false
!

isHidden
    "return true, if the receiver represents a hidden file.
     On UNIX, a name starting with a period is considered hidden."

    ^ self baseName startsWith:'.'
!

isImplicit
    "return true, if the receiver represents builtin names such as '.' or '..'.
     On UNIX, a name starting with a period is considered hidden."

    |name|

    name := self baseName.
    ^ name = '.' or:[name = '..'].

    "Modified: 18.9.1997 / 18:03:28 / stefan"
! !

!UnixFilename class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.6 1997-12-15 10:33:38 cg Exp $'
! !