UnixFilename.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 07 Jul 2011 23:08:07 +0100
branchjv
changeset 17845 7e0cfaac936d
parent 17841 7abcc4aef871
child 17846 24edc476ac18
permissions -rw-r--r--
Merged with /trunk

"
 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.
"
"{ Package: 'stx:libbasic' }"

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.
"

!

examples
    "
        (self named:'/tmp/äöü') writeStream close
    "
! !

!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
!

nullFilename
    "Return /dev/null"

    ^ '/dev/null'

    "
     Filename nullFilename  
    "

    "Modified: / 14.1.1998 / 14:20:55 / stefan"
!

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"
!

separatorString
    "return the file/directory separator as a string."

    ^ '/'

    "
     Filename separatorString  
    "
! !

!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).
     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."

    |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    
     '../../libtool/bitmaps/SBrowser.xbm' asFilename fileType    
    "

    "Modified: / 21.7.1998 / 11:26:32 / 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."

    |baseName|

    baseName := self baseName.
    ^ ((baseName startsWith:'.') and:[baseName ~= '..'])
!

isImplicit
    "return true, if the receiver represents builtin names such as '.' or '..'.
     On UNIX, the current and parent dir names are considered implicit."

    |name|

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

    "Modified: / 18.9.1997 / 18:03:28 / stefan"
    "Modified: / 21.7.1998 / 11:10:42 / cg"
! !

!UnixFilename methodsFor:'special accessing'!

osNameForDirectory
    "internal - return the OS's name for the receiver to
     access it as a directory."

    ^ self osNameForFile
!

osNameForFile
    "internal - return the OS's name for the receiver to
     access it as a file."

    nameString bitsPerCharacter < 8 ifTrue:[
        ^ nameString.
    ].
    ^ nameString utf8Encoded.
! !

!UnixFilename class methodsFor:'documentation'!

version
    ^ '$Id: UnixFilename.st 10656 2011-07-07 22:08:07Z vranyj1 $'
!

version_CVS
    ^ '§Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.16 2009/10/28 14:02:12 cg Exp §'
! !