#§
#§ 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
}