author | Jan Vrany <jan.vrany@labware.com> |
Tue, 11 Jul 2023 12:13:27 +0100 | |
branch | jv |
changeset 1173 | e3dd2050492e |
parent 1156 | b6ca954ebfc9 |
permissions | -rw-r--r-- |
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
1 |
" |
1156
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
2 |
COPYRIGHT (c) 2020-2021 LabWare |
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
3 |
" |
117 | 4 |
"{ Package: 'stx:goodies/monticello' }" |
5 |
||
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
6 |
"{ NameSpace: Smalltalk }" |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
7 |
|
117 | 8 |
MCDirectoryRepository subclass:#MCSubDirectoryRepository |
9 |
instanceVariableNames:'' |
|
10 |
classVariableNames:'' |
|
11 |
poolDictionaries:'' |
|
688 | 12 |
category:'SCM-Monticello-Repositories' |
117 | 13 |
! |
14 |
||
15 |
MCSubDirectoryRepository comment:'A MCDirectoryRepository that looks in subdirectories too.' |
|
16 |
! |
|
17 |
||
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
18 |
!MCSubDirectoryRepository class methodsFor:'documentation'! |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
19 |
|
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
20 |
copyright |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
21 |
" |
1156
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
22 |
COPYRIGHT (c) 2020-2021 LabWare |
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
23 |
|
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
24 |
|
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
25 |
" |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
26 |
! ! |
117 | 27 |
|
908 | 28 |
!MCSubDirectoryRepository class methodsFor:'queries'! |
117 | 29 |
|
30 |
description |
|
31 |
^ 'directory with subdirectories' |
|
32 |
! ! |
|
33 |
||
34 |
!MCSubDirectoryRepository methodsFor:'as yet unclassified'! |
|
35 |
||
36 |
findFullNameForReading: aBaseName |
|
37 |
"Answer the latest version of aBaseName" |
|
38 |
| possible | |
|
190 | 39 |
possible := SortedCollection sortBlock: [ :a :b | b first modificationTime < a first modificationTime ]. |
117 | 40 |
self allDirectories |
41 |
do: [:dir | dir entries |
|
42 |
do: [:ent | ent isDirectory |
|
43 |
ifFalse: [ |
|
44 |
(ent name = aBaseName) ifTrue: [ possible add: {ent. dir fullNameFor: ent name}]]]]. |
|
45 |
^(possible at: 1 ifAbsent: [ ^nil ]) second |
|
190 | 46 |
|
117 | 47 |
! |
48 |
||
49 |
findFullNameForWriting: aBaseName |
|
50 |
| possible split dirScore fileScore prefix fpattern parts now | |
|
190 | 51 |
split := directory splitNameVersionExtensionFor: aBaseName. |
52 |
fpattern := split first, '*'. |
|
53 |
possible := SortedCollection sortBlock: [ :a :b | |
|
117 | 54 |
a first = b first |
55 |
ifTrue: [ a second = b second |
|
56 |
ifFalse: [ a second < b second ] |
|
57 |
ifTrue: [ a third fullName size < b third fullName size ]] |
|
58 |
ifFalse: [ a first > b first ] ]. |
|
190 | 59 |
now := Time totalSeconds. |
60 |
prefix := directory pathParts size. |
|
117 | 61 |
self allDirectories do: [:dir | |
190 | 62 |
parts := dir pathParts allButFirst: prefix. |
63 |
dirScore := (parts select: [ :part | fpattern match: part ]) size. |
|
64 |
fileScore := (dir entries collect: [ :ent | |
|
117 | 65 |
(ent isDirectory not and: [ fpattern match: ent name ]) |
66 |
ifFalse: [ SmallInteger maxVal ] |
|
67 |
ifTrue: [ now - ent modificationTime ]]). "minimum age" |
|
190 | 68 |
fileScore := fileScore isEmpty ifTrue: [ SmallInteger maxVal ] |
117 | 69 |
ifFalse: [ fileScore min ]. |
70 |
possible add: { dirScore. fileScore. dir } ]. |
|
71 |
^ (possible first third) fullNameFor: aBaseName |
|
72 |
! |
|
73 |
||
74 |
readStreamForFileNamed: aString do: aBlock |
|
75 |
| file val | |
|
190 | 76 |
file := FileStream readOnlyFileNamed: (self findFullNameForReading: aString). |
77 |
val := aBlock value: file. |
|
117 | 78 |
file close. |
79 |
^ val |
|
80 |
! |
|
81 |
||
82 |
writeStreamForFileNamed: aString replace: aBoolean do: aBlock |
|
83 |
| file | |
|
84 |
file := aBoolean |
|
85 |
ifTrue: [FileStream |
|
86 |
forceNewFileNamed: (self findFullNameForReading: aString)] |
|
87 |
ifFalse: [FileStream |
|
88 |
newFileNamed: (self findFullNameForWriting: aString)]. |
|
89 |
aBlock value: file. |
|
90 |
file close |
|
91 |
! ! |
|
92 |
||
93 |
!MCSubDirectoryRepository methodsFor:'enumeration'! |
|
94 |
||
95 |
allDirectories |
|
96 |
| remaining dir dirs | |
|
97 |
remaining := OrderedCollection new. |
|
98 |
dirs := OrderedCollection new. |
|
99 |
remaining addLast: directory. |
|
100 |
[remaining isEmpty] |
|
101 |
whileFalse: [dir := remaining removeFirst. |
|
102 |
dirs add: dir. |
|
103 |
dir entries |
|
104 |
do: [:ent | ent isDirectory |
|
105 |
ifTrue: [remaining |
|
106 |
addLast: (dir directoryNamed: ent name)]]]. |
|
107 |
^ dirs |
|
108 |
! |
|
109 |
||
110 |
allFileNames |
|
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
111 |
"sorting {entry. dirName. name}" |
117 | 112 |
|
1121
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
113 |
| sorted | |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
114 |
sorted := SortedCollection sortBlock: [:a :b | |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
115 |
a first modificationTime >= b first modificationTime ]. |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
116 |
self allDirectories |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
117 |
do: [:dir | dir directoryContentsAsFilenames |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
118 |
do: [:ent | ent isDirectory |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
119 |
ifFalse: [sorted add: {ent. dir pathName. ent baseName}]]]. |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
120 |
^ sorted |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
121 |
collect: [:ea | ea third ] |
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
122 |
|
c5661215109c
Tonel: various fixes here and there (part 2)
Jan Vrany <jan.vrany@labware.com>
parents:
908
diff
changeset
|
123 |
"Modified: / 03-07-2020 / 20:30:06 / Jan Vrany <jan.vrany@labware.com>" |
117 | 124 |
! ! |
125 |
||
126 |
!MCSubDirectoryRepository methodsFor:'user interface'! |
|
127 |
||
128 |
description |
|
129 |
^ directory pathName, '/*' |
|
130 |
! ! |
|
131 |
||
132 |
!MCSubDirectoryRepository class methodsFor:'documentation'! |
|
133 |
||
273 | 134 |
version |
908 | 135 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCSubDirectoryRepository.st,v 1.5 2014-02-12 14:53:39 cg Exp $' |
273 | 136 |
! |
137 |
||
190 | 138 |
version_CVS |
908 | 139 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCSubDirectoryRepository.st,v 1.5 2014-02-12 14:53:39 cg Exp $' |
190 | 140 |
! |
141 |
||
1156
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
142 |
version_HG |
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
143 |
|
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
144 |
^ '$Changeset: <not expanded> $' |
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
145 |
! |
b6ca954ebfc9
Use custom Smalltalk/X package loader(s)
Jan Vrany <jan.vrany@labware.com>
parents:
1121
diff
changeset
|
146 |
|
190 | 147 |
version_SVN |
908 | 148 |
^ '$Id: MCSubDirectoryRepository.st,v 1.5 2014-02-12 14:53:39 cg Exp $' |
117 | 149 |
! ! |
908 | 150 |