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