UnixFilename.st
author Stefan Vogel <sv@exept.de>
Fri, 10 Jan 2020 15:35:15 +0100
changeset 25185 c69a46903233
parent 24571 3212bdd81ab6
permissions -rw-r--r--
#QUALITY by stefan class: CharacterEncoder changed: #encodingError (send #ifTrue: instead of #ifFalse:)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23042
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
     1
"{ Encoding: utf8 }"
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
     2
2943
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
     3
"
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
     4
 COPYRIGHT (c) 1997 by eXept Software AG
3125
543358373041 care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents: 2943
diff changeset
     5
	      All Rights Reserved
2943
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
     6
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
     7
 This software is furnished under a license and may be used
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
     8
 only in accordance with the terms of that license and with the
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
    10
 be provided or otherwise made available to, or used by, any
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
    11
 other person.  No title to or ownership of the software is
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
    12
 hereby transferred.
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
    13
"
7939
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    14
"{ Package: 'stx:libbasic' }"
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    15
19818
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
    16
"{ NameSpace: Smalltalk }"
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
    17
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Filename subclass:#UnixFilename
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:''
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'OS-Unix'
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    25
!UnixFilename class methodsFor:'documentation'!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    26
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    27
copyright
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    28
"
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    29
 COPYRIGHT (c) 1997 by eXept Software AG
3125
543358373041 care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents: 2943
diff changeset
    30
	      All Rights Reserved
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    31
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    32
 This software is furnished under a license and may be used
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    33
 only in accordance with the terms of that license and with the
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    35
 be provided or otherwise made available to, or used by, any
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    36
 other person.  No title to or ownership of the software is
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    37
 hereby transferred.
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    38
"
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    39
!
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
    40
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    41
documentation
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    42
"
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    43
    Filenames in Unix.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    44
"
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    45
11318
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
    46
!
7939
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    47
11318
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
    48
examples
7939
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    49
    "
23042
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
    50
        (self named:'/tmp/äöü') writeStream close
7939
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    51
    "
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    52
! !
3a8b75e8f804 catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents: 3664
diff changeset
    53
17047
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    54
!UnixFilename class methodsFor:'defaults'!
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    55
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    56
defaultTempDirectoryName
23042
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
    57
    "return the default temp directory as a filename.
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
    58
     By default, this is '/tmp', but can be overriden by one of
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
    59
     the shell variables: ('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP')"
17047
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    60
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    61
    |tempDirString tempDir|
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    62
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    63
    #('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar |
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    64
        tempDirString := OperatingSystem getEnvironment:envVar.
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    65
        tempDirString notNil ifTrue:[
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    66
            tempDir := self named:tempDirString.    
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    67
            (tempDir exists and:[ tempDir isWritable ]) ifTrue:[
17073
10f589aa4409 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 17047
diff changeset
    68
                ('Filename [info]: using tmp folder "%1" as specified by environment: "%2"'
17075
ff03935f9141 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 17073
diff changeset
    69
                    bindWith:tempDir pathName with:envVar) infoPrintCR.
17047
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    70
                ^ tempDir asFilename.
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    71
            ].
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    72
        ].
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    73
    ].
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    74
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    75
    tempDir := '/tmp' asFilename.
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    76
    ('Filename [info]: using default unix tmp folder: ',tempDir pathName) infoPrintCR.
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    77
    ^ tempDir    
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    78
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    79
    "
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    80
     Filename defaultTempDirectoryName
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    81
     Filename defaultTempDirectoryName exists
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    82
     Filename defaultTempDirectoryName isWritable
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    83
    "
23042
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
    84
def1ea6ee127 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22276
diff changeset
    85
    "Modified (comment): / 31-05-2018 / 09:56:20 / Claus Gittinger"
17047
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    86
! !
add3f6361c26 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16754
diff changeset
    87
23600
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    88
!UnixFilename class methodsFor:'misc'!
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    89
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    90
nameWithSpecialExpansions:aString
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    91
    "return the nameString, expanding any OS specific macros.
24571
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
    92
     Here, a ~/ or ~user/ prefix is expanded to the user's home dir (as in csh)"
23600
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    93
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    94
    |expandedString|
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    95
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    96
    expandedString := aString.
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    97
    (expandedString includes:$$) ifTrue:[
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    98
        expandedString := OperatingSystem expandEnvironmentStrings:expandedString.
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
    99
    ].
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   100
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   101
    (expandedString startsWith:$~) ifTrue:[
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   102
        ^ super nameWithSpecialExpansions:expandedString.
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   103
    ].
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   104
    ^ expandedString
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   105
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   106
    "
24571
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   107
     self nameWithSpecialExpansions:'/usr/lib'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   108
     self nameWithSpecialExpansions:'$JAVA_HOME/bin'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   109
     self nameWithSpecialExpansions:'${JAVA_HOME}/bin'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   110
     self nameWithSpecialExpansions:'${JAVA_HOME}-tttttt'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   111
     self nameWithSpecialExpansions:'$(JAVA_HOME)/bin'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   112
     self nameWithSpecialExpansions:'$(JAVA_HOME)bin'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   113
     self nameWithSpecialExpansions:'~/work'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   114
     self nameWithSpecialExpansions:'~stefan/test'
3212bdd81ab6 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 23624
diff changeset
   115
     self nameWithSpecialExpansions:'/Users/exept/cg_work/exept/expecco/application/expecco_dmg/Applications'
23600
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   116
    "
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   117
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   118
    "Created: / 10-01-2019 / 16:04:14 / Stefan Vogel"
23624
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   119
    "Modified (comment): / 21-01-2019 / 16:46:34 / Stefan Vogel"
23600
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   120
! !
f7a4056adc93 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23042
diff changeset
   121
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
!UnixFilename class methodsFor:'queries'!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
isBadCharacter:aCharacter
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    "return true, if aCharacter is unallowed in a filename."
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    aCharacter == $/ ifTrue:[^ true].
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
    ^ super isBadCharacter:aCharacter
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
    "Created: 8.9.1997 / 00:13:14 / cg"
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   133
isCaseSensitive
19818
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
   134
    "return true, if filenames are case sensitive.
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
   135
     This is not really correct, as the sensitivity may depend on
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
   136
     the paricular mounted file system (NFS, for example)"
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   137
14818
bf4f76418acf class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 14569
diff changeset
   138
    ^ OperatingSystem caseSensitiveFilenames
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   139
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   140
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   141
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   142
    "Return /dev/null"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   143
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   144
    ^ '/dev/null'
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   145
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   146
    "
8752
3e7429854c55 comments
Stefan Vogel <sv@exept.de>
parents: 8245
diff changeset
   147
     Filename nullFilename  
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   148
    "
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   149
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   150
    "Modified: / 14.1.1998 / 14:20:55 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   151
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3125
diff changeset
   152
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   153
parentDirectoryName
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   154
    "return the name used for the parent directory.
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   155
     This is '..' for unix and dos-like systems.
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   156
     (there may be more in the future."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   157
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   158
    ^ '..'
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   159
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2907
diff changeset
   160
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
separator
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "return the file/directory separator."
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
     ^ $/
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
     "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
      Filename concreteClass separator  
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
     "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    "Created: 8.9.1997 / 00:18:14 / cg"
8245
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   171
!
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   172
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   173
separatorString
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   174
    "return the file/directory separator as a string."
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   175
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   176
    ^ '/'
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   177
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   178
    "
8752
3e7429854c55 comments
Stefan Vogel <sv@exept.de>
parents: 8245
diff changeset
   179
     Filename separatorString  
8245
343908a8a4e1 separatorString / separator
Claus Gittinger <cg@exept.de>
parents: 7939
diff changeset
   180
    "
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
! !
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
!UnixFilename methodsFor:'file queries'!
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
fileType
21276
a44b5531d0dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19818
diff changeset
   186
    "this returns a string describing the type of contents of the file. 
a44b5531d0dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19818
diff changeset
   187
     This is done using the unix 'file' command,
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
     (which usually is configurable by /etc/magic).
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   189
     Warning:
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   190
         Since the returned string differs among systems (and language settings),
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   191
         it is only useful for user-information; 
21276
a44b5531d0dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19818
diff changeset
   192
         NOT as a tag to be used by a program.
a44b5531d0dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19818
diff changeset
   193
         For this, use mimeType or mimeTypeOfContents."
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
16581
93a7592ed3bd class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 15809
diff changeset
   195
    |typeString|
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
16754
0e2a27636731 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16581
diff changeset
   197
    "/ since executing 'file' takes some time, the most common
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    "/ ones are checked first, using the general fileType implementation. 
16754
0e2a27636731 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16581
diff changeset
   199
    "/ (also, the file-command is only available on Unix systems,
0e2a27636731 class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 16581
diff changeset
   200
    "/ so this provides a reasonable fallback).
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    typeString := super fileType.
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
    typeString ~= 'file' ifTrue:[^ typeString].
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
22276
07e8e8a1bfbd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21276
diff changeset
   205
    typeString := PipeStream outputFromCommand:('/usr/bin/file "' , self pathName , '"').
16581
93a7592ed3bd class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 15809
diff changeset
   206
    typeString notNil ifTrue:[
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   207
        typeString := typeString copyFrom:(typeString indexOf:$:) + 1.
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   208
        typeString := typeString withoutSeparators
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    ].
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    ^ typeString
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
     'Makefile' asFilename fileType 
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
     '.' asFilename fileType     
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
     '/dev/null' asFilename fileType        
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
     'smalltalk.rc' asFilename fileType    
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
     'bitmaps/SBrowser.xbm' asFilename fileType    
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   218
     '../../libtool/bitmaps/SBrowser.xbm' asFilename fileType    
16581
93a7592ed3bd class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 15809
diff changeset
   219
     './stx' asFilename fileType    
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
    "
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
22276
07e8e8a1bfbd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21276
diff changeset
   222
    "Modified: / 21-07-1998 / 11:26:32 / cg"
07e8e8a1bfbd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21276
diff changeset
   223
    "Modified: / 21-09-2017 / 11:09:52 / stefan"
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
! !
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   226
!UnixFilename methodsFor:'queries'!
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   227
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   228
isExplicitRelative
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   229
    "return true, if this name is an explicit relative name
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   230
     (i.e. starts with './' or '../', to avoid path-prepending)"
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   231
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   232
    (nameString startsWith:'./') ifTrue:[
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   233
	^ true
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   234
    ].
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   235
    (nameString startsWith:'../') ifTrue:[
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   236
	^ true
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   237
    ].
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   238
    ^ false
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   239
!
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   240
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   241
isHidden
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   242
    "return true, if the receiver represents a hidden file.
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   243
     On UNIX, a name starting with a period is considered hidden."
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   244
12390
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   245
    |baseName|
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   246
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   247
    baseName := self baseName.
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   248
    ^ ((baseName startsWith:'.') and:[baseName ~= '..'])
2943
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   249
!
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   250
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   251
isImplicit
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   252
    "return true, if the receiver represents builtin names such as '.' or '..'.
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   253
     On UNIX, the current and parent dir names are considered implicit."
2943
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   254
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   255
    |name|
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   256
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   257
    name := self baseName.
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   258
    ^ name = '.' or:[name = '..'].
89dee83077bd Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2931
diff changeset
   259
3664
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   260
    "Modified: / 18.9.1997 / 18:03:28 / stefan"
7bcbf8c6c2cf comments;
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
   261
    "Modified: / 21.7.1998 / 11:10:42 / cg"
2931
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   262
! !
11bcbf8738c6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   263
11318
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
   264
!UnixFilename methodsFor:'special accessing'!
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
   265
14221
d2ef1c042257 Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 12390
diff changeset
   266
osName
d2ef1c042257 Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 12390
diff changeset
   267
    "redefined from superclass, because we do not distinguish file and directory names"
11318
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
   268
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
   269
    ^ self osNameForFile
23624
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   270
!
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   271
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   272
osNameForFile
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   273
    "internal - return the OS's name for the receiver to
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   274
     access it as a file."
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   275
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   276
    (nameString size == 0 
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   277
     or:[nameString first ~~ $~ 
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   278
         and:[(nameString includes:$$) not]]) ifTrue:[
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   279
        ^ nameString.
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   280
    ].
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   281
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   282
    ^ self species nameWithSpecialExpansions:nameString.
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   283
5c6834205e82 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23600
diff changeset
   284
    "Created: / 21-01-2019 / 15:58:18 / Stefan Vogel"
11318
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
   285
! !
fc07976462e8 Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents: 9940
diff changeset
   286
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   287
!UnixFilename class methodsFor:'documentation'!
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
   289
version
19818
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
   290
    ^ '$Header$'
12390
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   291
!
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   292
42abbd021501 changed: #isHidden
Claus Gittinger <cg@exept.de>
parents: 11318
diff changeset
   293
version_CVS
19818
8e5bdaeed613 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 17075
diff changeset
   294
    ^ '$Header$'
2907
1666bf27f351 VMS changes
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
! !
14818
bf4f76418acf class: UnixFilename
Claus Gittinger <cg@exept.de>
parents: 14569
diff changeset
   296