Menu

[r3]: / cmp / PkgLib / Check.tcl  Maximize  Restore  History

Download this file

239 lines (187 with data), 6.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#§ Compiler2 - PkgLib - Check
#§ (C) IPN - Ingenieurbuero fuer Praezisionsnumerik
#§ Dipl.-Ing. Andreas Otto
#§ Ulmenstrasse 3
#§ D-34289 Zierenberg
#§ mailto:aotto@t-online.de
#§ http://tclcompiler.sourceforge.net
#§ Alle Rechte vorbehalten
package require StdLib
package require FileLib
package require System
package require Md5Sum
namespace eval ::PkgLib::Check {
variable PKG
namespace import ::PkgLib::Db::*
}
proc ::PkgLib::Check::Msg { Str } {
puts stdout "PKG CHECK MSG: $Str"
}
proc ::PkgLib::Check::Msg2 { Str } {
puts -nonewline $Str
}
proc ::PkgLib::Check::Warning { Str } {
puts stdout "PKG CHECK WARNING: $Str"
}
proc ::PkgLib::Check::ErrorM { args } {
variable PKG
set NAME [ ResolvDbName $PKG ]
lappend args "please delete the package \"cct -t $NAME pkg --del\""
lappend args "and add the package \"cct -t $NAME pkg --add\""
lappend args "to rebuild the package database"
::StdLib::ErrorS [ list PKG CHECK $PKG ] $args
}
##
## -----------------------------------------------------------------
##
proc ::PkgLib::Check::Test-Exist { File } {
if {[ file exist $File ]} return
ErrorM "the original file \"$File\" does not exist"
return -code continue
}
proc ::PkgLib::Check::Test-Type { File Check } {
set TMP [ file type $File ]
if {[ string equal $TMP $Check ]} return
ErrorM "check failed for file:" \
"\"$File\"" \
"the existing file type \"$TMP\"" \
"is not the original file type \"$Check\""
return -code continue
}
proc ::PkgLib::Check::Test-Perm { File Check } {
global env
foreach { ARCH TMP } [ ::System::FilePermGet $File ] break
if { $env(COMPILER_ARCH) != $ARCH || $TMP == $Check } return
ErrorM "check failed for file:" \
"\"$File\"" \
"the existing permissions \"$TMP\"" \
"are not the original permissions \"$Check\""
return -code continue
}
proc ::PkgLib::Check::Test-Link { File Check } {
set TMP [ file readlink $File ]
if {[ string equal $TMP $Check ]} return
ErrorM "check failed for file:" \
"\"$File\"" \
"the existing link target \"$TMP\"" \
"is not the original link target \"$Check\""
return -code continue
}
proc ::PkgLib::Check::Test-MdF { File Check } {
set TMP [ ::Md5Sum::file $File ]
if {[ string equal $TMP $Check ] || $TMP == "§SKIP§" } return
ErrorM "check failed for file:" \
"\"$File\"" \
"the existing md5sum \"$TMP\"" \
"is not the original md5sum \"$Check\""
}
##
## -----------------------------------------------------------------
##
proc ::PkgLib::Check::Main { pKG } {
variable PKG
set HOME [ ::PkgLib::COMPILER_HOME ]
##
Msg "check package-files"
##
::StdLib::Push ERROR PUTS
foreach PKG [ DbPKG $pKG ] {
##
Msg2 "\n [ format {check package %20s -> } $PKG ]"
##
set INSTDIR [ ::PkgLib::INSTDIR $PKG ]
##
Msg2 "dir, file, link"
##
foreach Line [ ::PkgLib::Db::Read-FILE_LIST $INSTDIR ] {
foreach { Typ Tgt Mode MdF } $Line break
if {[ string equal [ file pathtype $Tgt ] {relative} ]} {
set Tgt [ file join $HOME $Tgt ]
}
Test-Exist $Tgt
switch -exact $Typ {
l { Test-Type $Tgt link
Test-Link $Tgt $Mode
}
f { Test-Type $Tgt file
Test-Perm $Tgt $Mode
Test-MdF $Tgt $MdF
}
d { Test-Type $Tgt directory
Test-Perm $Tgt $Mode
}
}
}
}
::StdLib::Pop ERROR
##
Msg2 "\n\n"
##
##
Msg "finish part 1"
##
return
}
proc ::PkgLib::Check::Main2 {{ CLEAN 0 }} {
set HOME [ ::PkgLib::COMPILER_HOME ]
##
Msg "check part 1 -> find unused install template"
##
## 1. setup all available packages
set _TMP {}
foreach P [ DbLIST ] { lappend _TMP $P 1 }
array set __TMP $_TMP
## 2. check with available install directories
set _TMP {}
foreach T [ glob -nocomplain -directory [ ::PkgLib::INSTDIR {} ] -types f .* ] {
set _T [ string range [ file tail $T ] 1 end ]
if {![ info exists __TMP($_T) ]} {
Warning "found unused install template \"$_T\""
continue
}
foreach L [ ::PkgLib::Db::Read-FILE_LIST [ ::PkgLib::INSTDIR $_T ] ] {
foreach { T P } $L break
if {[ string equal [ file pathtype $P ] {relative} ]} {
set P [ file join $HOME $P ]
}
lappend _TMP $P $_T
}
}
array unset __TMP
array set __TMP $_TMP
##
Msg "finish part 1"
##
##
Msg "check part 2 -> find non \"cct\" package files"
##
set SKIP [ list [ file join $HOME var ] \
[ file join $HOME cct ] \
[ file join $HOME cgi.sh ] \
[ file join $HOME CCT.BAT ] \
[ file join $HOME CGI.BAT ] \
[ file join $HOME exe * lib pkgIndex.tcl ] \
[ file join $HOME exe * lib pkg pkgIndex.tcl ] \
[ file join $HOME exe * lib pkg Cct.cfg ] \
[ file join $HOME exe * lib pkg Cgi.cfg ] \
]
::FileLib::Push-SKIP $SKIP
::StdLib::Push ERROR EXIT
set ARGS [ concat -nocomplain -directory $HOME -types {f l} .* * ]
foreach T [ ::FileLib::GetTree $ARGS ] {
if {[ info exists __TMP($T) ]} continue
Warning "found non package file \"$T\""
if { $CLEAN } { ::FileLib::Delete $T }
}
::StdLib::Pop ERROR
::FileLib::Pop-SKIP
##
Msg "finish part 2"
##
return
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.