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