DirectoryContents.st
author Claus Gittinger <cg@exept.de>
Tue, 20 Sep 2016 11:51:13 +0200
changeset 4086 0dc6dd61e485
parent 3831 8fc6245e8c39
child 4299 54a7d553b06e
child 4769 89914ccfcf7d
permissions -rw-r--r--
#FEATURE by cg class: DirectoryContents changed: #directory: #directoryNamed:detect:onOpenErrorDo: also handle StreamErrors (OS-errors)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4086
0dc6dd61e485 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3831
diff changeset
     1
"{ Encoding: utf8 }"
0dc6dd61e485 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3831
diff changeset
     2
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     3
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     4
 COPYRIGHT (c) 1997 by eXept Software AG
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     5
              All Rights Reserved
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     6
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     7
 This software is furnished under a license and may be used
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    12
 hereby transferred.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    13
"
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
    15
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
    16
"{ NameSpace: Smalltalk }"
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
    17
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    18
Object subclass:#DirectoryContents
2079
ca
parents: 2078
diff changeset
    19
	instanceVariableNames:'directory timeStamp contents isReadable isRootDirectory accessKey'
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    20
	classVariableNames:'CachedDirectories LockSema ReadersList'
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    21
	poolDictionaries:''
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    22
	category:'System-Support'
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    23
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    24
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    25
Object subclass:#DirectoryContentsItem
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
    26
	instanceVariableNames:'info fileName'
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
    27
	classVariableNames:'CachedRemoteMountPoints CachedRemoteMountPointsTimeStamp'
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    28
	poolDictionaries:''
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    29
	privateIn:DirectoryContents
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    30
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    31
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    32
!DirectoryContents class methodsFor:'documentation'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    33
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    34
copyright
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    35
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    36
 COPYRIGHT (c) 1997 by eXept Software AG
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    37
              All Rights Reserved
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    38
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    39
 This software is furnished under a license and may be used
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    40
 only in accordance with the terms of that license and with the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    41
 inclusion of the above copyright notice.   This software may not
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    42
 be provided or otherwise made available to, or used by, any
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    43
 other person.  No title to or ownership of the software is
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    44
 hereby transferred.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    45
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    46
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    47
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    48
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    49
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    50
documentation
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    51
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    52
    DirectoryContents provides a cached view onto a fileDirectory.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    53
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    54
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    55
    Notice:
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    56
        This class is not available in other ST-systems;
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    57
        Applications using it may not be portable.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    58
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    59
    [author:]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    60
        Claus Atzkern
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    61
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    62
    [see also:]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    63
        Filename
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    64
        FileStream DirectoryStream OperatingSystem
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    65
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    66
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    67
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    68
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    69
!DirectoryContents class methodsFor:'initialization'!
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    70
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    71
initialize
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    72
    "setup lock-mechanism
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    73
    "
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    74
    LockSema    := RecursionLock new.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    75
    ReadersList := Dictionary new.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    76
! !
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    77
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    78
!DirectoryContents class methodsFor:'instance creation'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    79
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    80
new
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    81
    ^ self basicNew initialize
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    82
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    83
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    84
!DirectoryContents class methodsFor:'accessing'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    85
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    86
cachedDirectoryNamed:aFileOrString
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    87
    "answer the valid cached directory or nil"
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    88
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    89
    ^ self directoryAt:aFileOrString
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    90
!
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    91
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    92
directoryNamed:aDirectory
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    93
    "returns the DirectoryContents for a directory named 
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    94
     aDirectoryName, aString, nil or Filename
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    95
    "
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
    96
    |directory contents lockRead pathName addToList|
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    97
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
    98
    aDirectory isNil ifTrue:[^ nil].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
    99
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   100
    directory := aDirectory asFilename.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   101
    directory exists ifFalse:[ ^ nil ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   102
1105
556e633a86c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1102
diff changeset
   103
    directory := directory asAbsoluteFilename.
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   104
    contents := nil.
620
2a40beccf337 - useing Filename to read contents of a directory
ca
parents: 616
diff changeset
   105
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   106
    LockSema critical:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   107
        CachedDirectories notNil ifTrue:[
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   108
            "/ remove all obsolete directories - without doing a system call
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   109
            CachedDirectories := CachedDirectories select:[:aDir| aDir timeStamp notNil ].
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   110
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   111
            contents := self directoryAt:directory.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   112
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   113
            contents isNil ifTrue:[
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   114
                |n max|
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   115
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   116
                max := self maxCachedDirectories.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   117
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   118
                CachedDirectories size > max ifTrue:[
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   119
                    "/ remove directories with contents less 64 and not obsolete (system call)
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   120
                    CachedDirectories := CachedDirectories
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   121
                        select:[:aDir| (aDir size > 64 and:[aDir isObsolete not]) ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   122
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   123
                    n := CachedDirectories size + 2 - max.
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   124
                    n > 0 ifTrue:[
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   125
                        "/ remove oldest directories
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   126
                        CachedDirectories removeLast:n.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   127
                    ].
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   128
                ].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   129
            ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   130
        ].
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   131
        contents isNil ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   132
            ReadersList isNil ifTrue:[ReadersList := Dictionary new].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   133
            pathName := directory pathName.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   134
            lockRead := ReadersList at:pathName ifAbsentPut:[Semaphore forMutualExclusion].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   135
        ]
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   136
    ].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   137
    contents notNil ifTrue:[^ contents].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   138
    addToList := false.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   139
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   140
    lockRead critical:[
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   141
        [  "/ test whether another task got the semaphore and
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   142
           "/ has read the directory contents
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   143
           (contents := self directoryAt:directory) isNil ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   144
                "/ read the directory contents
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   145
                contents  := self new directory:directory.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   146
                "/ only cache if the mod'Time is valid.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   147
                addToList := contents timeStamp notNil.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   148
            ]
1022
6a288db5312a #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 974
diff changeset
   149
        ] ensure:[
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   150
            LockSema critical:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   151
                addToList ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   152
                    CachedDirectories isNil ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   153
                        CachedDirectories := OrderedCollection new
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   154
                    ].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   155
                    CachedDirectories add:contents
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   156
                ].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   157
                (lockRead isEmpty and:[ReadersList notNil]) ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   158
                    ReadersList removeKey:pathName ifAbsent:nil
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   159
                ]
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   160
            ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   161
        ]
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   162
    ].    
620
2a40beccf337 - useing Filename to read contents of a directory
ca
parents: 616
diff changeset
   163
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   164
    ^ contents
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   165
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   166
616
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   167
!DirectoryContents class methodsFor:'cache flushing'!
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   168
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   169
flushCache
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   170
    "flush list of remembered directory contents"
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   171
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   172
    LockSema critical:[ CachedDirectories := nil ].
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   173
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   174
    "
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   175
     self flushCache
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   176
    "
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   177
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   178
    "Created: / 11.2.2000 / 00:13:59 / cg"
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   179
!
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   180
1105
556e633a86c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1102
diff changeset
   181
flushCachedDirectoryFor:aDirectoryOrString
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   182
    "remove directory from cache
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   183
    "
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   184
    |directory|
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   185
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   186
    aDirectoryOrString isNil ifTrue:[^ self ].                   
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   187
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   188
    directory := aDirectoryOrString asFilename.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   189
    directory isSymbolicLink ifTrue:[^ self].
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   190
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   191
    self
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   192
        directoryAt:directory
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   193
        checkForValidContentsDo:[:aDirectory| false ].  "/ should be removed from cache
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   194
!
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   195
695
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   196
lowSpaceCleanup
1575
Stefan Vogel <sv@exept.de>
parents: 1468
diff changeset
   197
    "flush list of remembered directory contents when low on memory"
695
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   198
1134
66f96c472a47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1105
diff changeset
   199
    self flushCache
695
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   200
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   201
    "
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   202
     self lowSpaceCleanup
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   203
    "
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   204
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   205
    "Created: / 18.2.1998 / 18:17:05 / cg"
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   206
    "Modified: / 24.9.1998 / 17:51:15 / cg"
616
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   207
! !
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   208
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   209
!DirectoryContents class methodsFor:'constants'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   210
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   211
maxCachedDirectories
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   212
    "returns number of maximum cached directories
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   213
    "
616
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   214
    ^ 20
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   215
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   216
    "Modified: / 25.2.1998 / 19:56:24 / cg"
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   217
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   218
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   219
!DirectoryContents class methodsFor:'private'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   220
2079
ca
parents: 2078
diff changeset
   221
accessKeyForDirectory:aDirectoryOrString
ca
parents: 2078
diff changeset
   222
    "computes a fast access key to retrieve the directory in the cache
ca
parents: 2078
diff changeset
   223
    "
ca
parents: 2078
diff changeset
   224
    |key last|
ca
parents: 2078
diff changeset
   225
    
ca
parents: 2078
diff changeset
   226
    aDirectoryOrString isNil ifTrue:[^ nil ].
ca
parents: 2078
diff changeset
   227
ca
parents: 2078
diff changeset
   228
    aDirectoryOrString isFilename ifTrue:[ key := aDirectoryOrString nameString ]
ca
parents: 2078
diff changeset
   229
                                 ifFalse:[ key := aDirectoryOrString ].
ca
parents: 2078
diff changeset
   230
ca
parents: 2078
diff changeset
   231
    key size > 1 ifTrue:[
ca
parents: 2078
diff changeset
   232
        last := key last.
ca
parents: 2078
diff changeset
   233
        (last == $/ or:[last == $\]) ifTrue:[
2989
4b2ec07a1de6 Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 2749
diff changeset
   234
            ^ key copyButLast:1.
2079
ca
parents: 2078
diff changeset
   235
        ].
ca
parents: 2078
diff changeset
   236
    ].
ca
parents: 2078
diff changeset
   237
    ^ key
ca
parents: 2078
diff changeset
   238
!
ca
parents: 2078
diff changeset
   239
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   240
directoryAt:aFileOrString
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   241
    "checks whether directory already exists and is valid.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   242
     If true the directory is returned otherwise nil
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   243
    "
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   244
    ^ self
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   245
        directoryAt:aFileOrString
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   246
        checkForValidContentsDo:[:aContents| aContents isObsolete not ].
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   247
!
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   248
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   249
directoryAt:aFileOrString checkForValidContentsDo:checkIsValidBlock
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   250
    "answer the directoryContents stored under aFileOrString in the cache.
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   251
     If the evaluation of the checkIsValidBlock returns false, the contents
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   252
     will be removed from the cache and nil is returned."
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   253
2079
ca
parents: 2078
diff changeset
   254
    |index directory file fastKey|
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   255
2079
ca
parents: 2078
diff changeset
   256
    fastKey := self accessKeyForDirectory:aFileOrString.
ca
parents: 2078
diff changeset
   257
    fastKey isNil ifTrue:[^ nil ].  "/ the name is nil
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   258
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   259
    directory := nil.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   260
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   261
    LockSema critical:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   262
        CachedDirectories notNil ifTrue:[
2079
ca
parents: 2078
diff changeset
   263
            index := CachedDirectories findFirst:[:d| d accessKey = fastKey ].
ca
parents: 2078
diff changeset
   264
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   265
            index == 0 ifTrue:[
2079
ca
parents: 2078
diff changeset
   266
                file  := aFileOrString asFilename asAbsoluteFilename.
ca
parents: 2078
diff changeset
   267
                index := CachedDirectories findFirst:[:d| d directory = file ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   268
            ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   269
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   270
            index ~~ 0 ifTrue:[
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   271
                directory := CachedDirectories removeAtIndex:index.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   272
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   273
                (checkIsValidBlock value:directory) ifTrue:[
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   274
                    "/ keep the last accessed directory at end
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   275
                    CachedDirectories add:directory.
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   276
                ] ifFalse:[
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   277
                    "/ validation block answers false - return nil and removed from cache
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   278
                    directory := nil.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   279
                ].
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   280
            ].
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   281
        ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   282
    ].
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   283
    ^ directory
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   284
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   285
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   286
!DirectoryContents class methodsFor:'queries'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   287
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   288
directoryNamed:aDirectoryName detect:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   289
    "evaluate the block, [:filename :isDirectory] on the directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   290
     contents of a directory named aDirectoryName, until the block
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   291
     returns true. If nothing detected false is returned
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   292
    "
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   293
    ^ self directoryNamed:aDirectoryName detect:aTwoArgBlock onOpenErrorDo:nil
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   294
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   295
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   296
directoryNamed:aDirectoryName detect:aTwoArgBlock onOpenErrorDo:exceptionBlock
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   297
    "evaluate the block, [:filename :isDirectory] on the directory
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   298
     contents of a directory named aDirectoryName, until the block
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   299
     returns true. If nothing detected false is returned.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   300
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   301
     if the directory cannot be open, the exceptionBlock is processed
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   302
     with the filename.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   303
    "
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   304
    |directory contents isReadable file|
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   305
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   306
    directory := aDirectoryName asFilename.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   307
    contents  := self directoryAt:directory.
620
2a40beccf337 - useing Filename to read contents of a directory
ca
parents: 616
diff changeset
   308
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   309
    contents notNil ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   310
        (isReadable := contents isReadable) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   311
            contents contentsDo:[:aFile :isDir|
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   312
                (aTwoArgBlock value:aFile value:isDir) ifTrue:[^ true]
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   313
            ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   314
            ^ false.
1155
edcf3cfe1e93 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1147
diff changeset
   315
        ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   316
    ] ifFalse:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   317
        (isReadable := directory exists) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   318
            [
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   319
                directory directoryContentsDo:[:fn |
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   320
                    file := directory construct:fn.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   321
                    (aTwoArgBlock value:file value:(file isDirectory)) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   322
                        ^ true
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   323
                    ]
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   324
                ].
4086
0dc6dd61e485 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3831
diff changeset
   325
            ] on:(FileStream openErrorSignal, StreamIOError) do:[:ex|
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   326
                isReadable := false.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   327
            ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   328
        ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   329
    ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   330
    (isReadable not and:[exceptionBlock notNil]) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   331
        exceptionBlock value:directory.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   332
    ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   333
    ^ false
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   334
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   335
3831
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   336
!DirectoryContents class methodsFor:'startup & release'!
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   337
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   338
preSnapshot
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   339
    "flush list of cached directory contents before saving a snapshot
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   340
     (do not save them in the image)"
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   341
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   342
    self flushCache.
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   343
! !
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   344
1102
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   345
!DirectoryContents class methodsFor:'utilities'!
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   346
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   347
contentsItemForFileName:aFilenameOrString 
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   348
    | aFilename directory directoryContents|
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   349
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   350
    aFilename := aFilenameOrString asFilename.
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   351
    directory := aFilename directory.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   352
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   353
    directoryContents := self directoryAt:directory.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   354
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   355
    directoryContents notNil ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   356
        directoryContents itemsDo:[:fileItemThere |
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   357
            fileItemThere fileName = aFilename ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   358
                ^ fileItemThere.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   359
            ].
1393
bb7048aaf86a care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
   360
        ].
bb7048aaf86a care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
   361
    ].
1252
933afe6d5bd6 care for directory being removed
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   362
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   363
    aFilename exists ifFalse:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   364
        directoryContents notNil ifTrue:[ directoryContents beObsolete ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   365
        ^ nil
1102
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   366
    ].
1105
556e633a86c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1102
diff changeset
   367
    ^ (DirectoryContentsItem new fileName:aFilename) info:aFilename info.
1102
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   368
! !
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   369
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   370
!DirectoryContents methodsFor:'accessing'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   371
2079
ca
parents: 2078
diff changeset
   372
accessKey
ca
parents: 2078
diff changeset
   373
    ^ accessKey
ca
parents: 2078
diff changeset
   374
!
ca
parents: 2078
diff changeset
   375
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   376
beObsolete
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   377
    "mark self as obsolete
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   378
     clear contents and reset time"
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   379
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   380
    |saveCont|
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   381
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   382
    timeStamp := nil.
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   383
    saveCont  := contents.
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   384
    contents  := #().
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   385
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   386
    saveCont notEmptyOrNil ifTrue:[
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   387
        "/ clear the info - if someone has a reference to the item
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   388
        saveCont do:[:eachItem | eachItem resetInfo ].
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   389
    ].
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   390
!
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   391
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   392
directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   393
    "returns the directoy name as Filename
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   394
    "
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   395
    ^ directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   396
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   397
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   398
modificationTime
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   399
    "get the last modification time of the directory.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   400
     Note that sometimes a root directory does not return
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   401
     a valid modification time - so do not cache it."
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   402
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   403
    |modifyTime|
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   404
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   405
    timeStamp isNil ifTrue:[^ nil].
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   406
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   407
    modifyTime := directory modificationTime.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   408
    modifyTime notNil ifTrue:[
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   409
        ^ modifyTime 
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   410
   ].
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   411
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   412
    isRootDirectory ifFalse:[
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   413
        "if it is not a root directory, assume that we have no access"
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   414
        isReadable := false.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   415
        self beObsolete.
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   416
    ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   417
    ^ nil
951
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   418
!
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   419
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   420
timeStamp
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   421
    "get the last timeStamp (when the directory info was read) of the directory
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   422
    "
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   423
    ^ timeStamp
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   424
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   425
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   426
!DirectoryContents methodsFor:'enumerating'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   427
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   428
contentsAndBaseNamesDo:aThreeArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   429
    "evaluate the block on each file; the argument to the block is the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   430
     filename, the baseName and true in case of a directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   431
     block arguments: [:fileName :aBaseName :isDirectory|
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   432
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   433
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   434
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   435
        aThreeArgBlock 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   436
            value:(eachItem fileName) 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   437
            value:(eachItem baseName ) 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   438
            value:(eachItem isDirectory)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   439
    ].
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   440
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   441
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   442
contentsDo:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   443
    "evaluate the block on each file; the argument to the block is the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   444
     filename and true in case of a directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   445
     block arguments: [:fileName :isDirectory|
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   446
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   447
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   448
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   449
        aTwoArgBlock
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   450
            value:(eachItem fileName) 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   451
            value:(eachItem isDirectory)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   452
    ].
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   453
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   454
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   455
directoriesAndBasenamesDo:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   456
    "evaluate block on each directory; a Filename and Basename.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   457
     The directories are sorted
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   458
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   459
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   460
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   461
        eachItem isDirectory ifTrue:[
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   462
            aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   463
        ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   464
    ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   465
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   466
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   467
directoriesDo:aOneArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   468
    "evaluate block on each directory; a Filename. The directories are sorted
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   469
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   470
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   471
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   472
        eachItem isDirectory ifTrue:[
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   473
            aOneArgBlock value:(eachItem fileName) 
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   474
        ]
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   475
    ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   476
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   477
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   478
filesAndBasenamesDo:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   479
    "evaluate block on each file; a Filename and a Basename.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   480
     The files are sorted.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   481
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   482
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   483
    self itemsDo:[:eachItem |
1324
e51285e95b3f not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 1296
diff changeset
   484
        eachItem isDirectory ifFalse:[
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   485
            aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   486
        ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   487
    ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   488
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   489
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   490
filesDo:aOneArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   491
    "evaluate block on each file; a Filename. The files are sorted.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   492
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   493
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   494
    self itemsDo:[:eachItem |
1324
e51285e95b3f not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 1296
diff changeset
   495
        eachItem isDirectory ifFalse:[
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   496
            aOneArgBlock value:(eachItem fileName)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   497
        ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   498
    ]
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   499
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   500
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   501
itemsDo:aBlock
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   502
    "evaluate the block on each contentsItem, which contains the fileName and type info"
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   503
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   504
    contents do:aBlock.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   505
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   506
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   507
!DirectoryContents methodsFor:'instance creation'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   508
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   509
directory:aFilename 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   510
    |time stream linkInfo sourcePath|
1155
edcf3cfe1e93 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1147
diff changeset
   511
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   512
    directory := aFilename asFilename.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   513
    isRootDirectory := directory isRootDirectory.
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   514
    accessKey := self class accessKeyForDirectory:directory.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   515
    contents := OrderedCollection new.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   516
    isReadable := false.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   517
    time := Timestamp now.
1155
edcf3cfe1e93 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1147
diff changeset
   518
    [
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   519
        [
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   520
            stream := DirectoryStream 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   521
                    directoryNamed:(directory osNameForDirectoryContents).
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   522
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   523
            stream notNil ifTrue:[
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   524
                [
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   525
                    (stream atEnd or:[ (linkInfo := stream nextLinkInfo) isNil ])
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   526
                ] whileFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   527
                    sourcePath := linkInfo sourcePath.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   528
                    (sourcePath = '.' or:[ sourcePath = '..' ]) ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   529
                        |fitem|
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   530
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   531
                        fitem := DirectoryContentsItem new 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   532
                                fileName:(directory construct:sourcePath)
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   533
                                linkInfo:linkInfo.
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   534
                        contents add:fitem.
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   535
                    ].
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   536
                ].
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   537
                isReadable := true.
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   538
            ].
4086
0dc6dd61e485 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3831
diff changeset
   539
        ] on:(FileStream openErrorSignal , StreamError) do:[:ex | isReadable := false. ].
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   540
    ] ensure:[
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   541
        stream notNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   542
            stream close
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   543
        ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   544
        isReadable ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   545
            contents := #()
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   546
        ].
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   547
    ].
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   548
    contents sort:[:a :b | a nameString < b nameString ].
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   549
    contents := contents asArray.
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   550
    timeStamp := time.
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   551
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   552
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   553
!DirectoryContents methodsFor:'obsolete'!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   554
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   555
updateContents
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   556
    <resource:#obsolete>
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   557
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   558
    "ensure that the file-info os present for every item
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   559
     ** obsolete - access info if required"
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   560
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   561
    "/    contents do:[:eachItem | eachItem updateInfo ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   562
! !
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   563
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   564
!DirectoryContents methodsFor:'printing'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   565
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   566
printOn:aStream
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   567
    aStream nextPutAll:'DirectoryContents of: '.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   568
    aStream nextPutAll:(directory pathName).
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   569
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   570
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   571
!DirectoryContents methodsFor:'queries'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   572
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   573
isObsolete
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   574
    "returns true if the directory contents represented by the receiver is obsolete
3303
b7f33985ea38 class: DirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3229
diff changeset
   575
     (i.e. if the fileSystem's directory has been changed in the meanwhile)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   576
    "
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   577
    |mt|
679
ce7aed726aff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 620
diff changeset
   578
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   579
    timeStamp isNil ifTrue:[^ true].
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   580
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   581
    mt := self modificationTime.
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   582
    mt isNil ifTrue:[^ true ].
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   583
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   584
    "we compare only seconds, since the modification time is not as (millisecond) accurate as the timestamp"
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   585
    timeStamp getSeconds < mt getSeconds ifTrue:[
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   586
        self beObsolete.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   587
        ^ true.
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   588
    ].
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   589
    ^ false
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   590
!
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   591
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   592
isReadable
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   593
    "answer true if the directory is readable
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   594
     no open error raised during reading the directory"
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   595
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   596
    ^ isReadable
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   597
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   598
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   599
isRootDirectory
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   600
    ^ isRootDirectory
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   601
!
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   602
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   603
size
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   604
    "get number of files including directories in the directory
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   605
    "
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   606
    ^ contents size
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   607
! !
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   608
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   609
!DirectoryContents methodsFor:'testing'!
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   610
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   611
includesIdentical:anItem
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   612
    ^ contents includesIdentical:anItem
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   613
!
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   614
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   615
isEmpty
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   616
    "returns true if directory is empty
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   617
    "
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   618
    ^ contents size == 0
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   619
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   620
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   621
isEmptyOrNil
2627
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   622
    "return true if I am nil or an empty collection" 
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   623
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   624
    ^ contents size == 0
2627
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   625
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   626
    "Modified (comment): / 17-08-2011 / 09:30:15 / cg"
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   627
!
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   628
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   629
notEmpty
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   630
    "returns true if directory is not empty
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   631
    "
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   632
    ^ contents size ~~ 0
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   633
!
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   634
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   635
notEmptyOrNil
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   636
    "returns true if directory is not empty
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   637
    "
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   638
    ^ contents size ~~ 0
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   639
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   640
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   641
!DirectoryContents::DirectoryContentsItem class methodsFor:'instance creation'!
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   642
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   643
fileName:aFilename
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   644
    ^ self new fileName:aFilename.
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   645
! !
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   646
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   647
!DirectoryContents::DirectoryContentsItem methodsFor:'accessing'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   648
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   649
baseName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   650
    ^ fileName baseName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   651
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   652
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   653
fileName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   654
    ^ fileName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   655
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   656
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   657
fileName:something
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   658
    "set the value of the instance variable 'fileName' (automatically generated)"
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   659
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   660
    fileName := something.
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   661
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   662
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   663
fileName:aFilename linkInfo:aLinkInfo
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   664
    fileName := aFilename.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   665
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   666
    (aLinkInfo notNil and:[aLinkInfo isValid])
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   667
        ifTrue:[self updateInfoFrom:aLinkInfo].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   668
!
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   669
1100
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   670
info
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   671
    info isNil ifTrue:[
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   672
        self updateInfo.
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   673
    ].
1100
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   674
    info isSymbol ifTrue:[^ nil]. "/ a remote directory
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   675
    ^ info
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   676
!
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   677
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   678
info:something
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   679
    "set the value of the instance variable 'type' (automatically generated)"
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   680
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   681
    info := something.
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   682
!
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   683
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   684
nameString
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   685
    "raw access to nameString"
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   686
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   687
    ^ fileName nameString
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   688
!
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   689
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   690
type
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   691
    info isNil ifTrue:[
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   692
        self updateInfo.
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   693
    ].
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   694
    info isSymbol ifTrue:[^ info].
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   695
    ^ info type
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   696
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   697
2745
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   698
!DirectoryContents::DirectoryContentsItem methodsFor:'converting'!
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   699
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   700
asFilename
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   701
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   702
    ^fileName
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   703
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   704
    "Created: / 08-05-2012 / 15:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   705
! !
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   706
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   707
!DirectoryContents::DirectoryContentsItem methodsFor:'misc'!
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   708
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   709
cachedRemoteMountPoints
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   710
    |mountPoints now|
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   711
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   712
    mountPoints := CachedRemoteMountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   713
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   714
    (mountPoints isNil
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   715
    or:[ CachedRemoteMountPointsTimeStamp isNil
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   716
    or:[ now := Timestamp now.
3229
c858bc4167dd class: DirectoryContents
Claus Gittinger <cg@exept.de>
parents: 2989
diff changeset
   717
         (now secondDeltaFrom: CachedRemoteMountPointsTimeStamp) > 30 
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   718
    ]]) ifTrue:[
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   719
        CachedRemoteMountPointsTimeStamp := now.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   720
        mountPoints := OperatingSystem mountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   721
        mountPoints := mountPoints select:[:mp | mp isRemote].
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   722
        CachedRemoteMountPoints := mountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   723
    ].
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   724
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   725
    ^ mountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   726
!
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   727
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   728
resetAttributes
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   729
    "reset the attributes... done if I'am a normal file"
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   730
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   731
    (info isNil or:[info isSymbol]) ifTrue:[^ self ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   732
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   733
    self isDirectory ifFalse:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   734
        info := nil.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   735
    ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   736
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   737
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   738
resetInfo
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   739
    info := nil.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   740
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   741
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   742
updateInfo
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   743
    "ensure that the file-info is present
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   744
        DirectoryContents flushCache
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   745
    "
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   746
    info isNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   747
        self updateInfoFrom:(fileName linkInfo).
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   748
    ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   749
!
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   750
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   751
updateInfoFrom:aLinkInfo
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   752
    "might be reused by updateLinkInfo"
2083
fb059bbd81e6 *** empty log message ***
ca
parents: 2082
diff changeset
   753
    |mountPoint nameString linkName|
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   754
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   755
    info := aLinkInfo.
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   756
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   757
    (info notNil and:[info isSymbolicLink]) ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   758
        OperatingSystem isMSWINDOWSlike ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   759
            linkName := info path.
2046
0ca98ed5fb80 handling of symbolic links
ca
parents: 1919
diff changeset
   760
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   761
            linkName notNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   762
                "have to check for both link and link target"
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   763
                mountPoint := self cachedRemoteMountPoints 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   764
                            detect:[:mInfo | |p|
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   765
                                p := mInfo mountPointPath.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   766
                                ((linkName startsWith:p) and:[ linkName startsWith:(p , '/') ])
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   767
                            ]
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   768
                            ifNone:nil.
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   769
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   770
                info := fileName info.  "get the info of the link target"   
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   771
            ].
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   772
        ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   773
    ] ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   774
        "have to check for mountPoint only"
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   775
        nameString := fileName name.
2083
fb059bbd81e6 *** empty log message ***
ca
parents: 2082
diff changeset
   776
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   777
        mountPoint := self cachedRemoteMountPoints 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   778
                    detect:[:mInfo | mInfo mountPointPath = nameString ]
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   779
                    ifNone:nil.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   780
    ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   781
    mountPoint notNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   782
        info := #remoteDirectory.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   783
    ] ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   784
        info isNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   785
            "/ broken symbolic link
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   786
            info := #symbolicLink.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   787
        ]
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   788
    ].
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   789
! !
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   790
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   791
!DirectoryContents::DirectoryContentsItem methodsFor:'printing'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   792
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   793
printOn:aStream
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   794
    aStream nextPutAll:'DirectoryContentsItem for: '.
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   795
    fileName printOn:aStream.
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   796
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   797
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   798
!DirectoryContents::DirectoryContentsItem methodsFor:'queries'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   799
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   800
isDirectory
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   801
    |t|
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   802
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   803
    t := self type.
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   804
    ^ (t == #directory or:[t == #remoteDirectory])
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   805
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   806
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   807
isRemoteDirectory
2074
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   808
    ^ self type == #remoteDirectory
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   809
!
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   810
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   811
isSpecialFile
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   812
    |type|
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   813
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   814
    type := self type.
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   815
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   816
    ^ (type ~~ #directory
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   817
        and:[type ~~ #remoteDirectory
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   818
        and:[type ~~ #regular
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   819
        and:[type ~~ #symbolicLink
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   820
    ]]])
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   821
!
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   822
2074
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   823
isSymbolicLink
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   824
    ^ self type == #symbolicLink
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   825
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   826
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   827
!DirectoryContents class methodsFor:'documentation'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   828
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   829
version
3831
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   830
    ^ '$Header$'
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   831
!
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   832
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   833
version_CVS
3831
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   834
    ^ '$Header$'
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   835
! !
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   836
2989
4b2ec07a1de6 Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 2749
diff changeset
   837
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   838
DirectoryContents initialize!