fix status

This commit is contained in:
Christian Zangl 2024-08-18 21:36:22 +02:00
parent 24b3a88576
commit 6f454f1836
No known key found for this signature in database
GPG Key ID: 6D468AC36E2A4B3D
5 changed files with 46 additions and 21 deletions

View File

@ -80,18 +80,18 @@ func (m *Main) log(text string) {
m.logger.Println(time.Now().UTC().Format("2006-01-02 15:04:05"), text)
}
func (m *Main) logStatus(stat chkbit.Status, path string) bool {
func (m *Main) logStatus(stat chkbit.Status, message string) bool {
if stat == chkbit.STATUS_UPDATE_INDEX {
m.numIdxUpd++
} else {
if stat == chkbit.STATUS_ERR_DMG {
m.total++
m.dmgList = append(m.dmgList, path)
m.dmgList = append(m.dmgList, message)
} else if stat == chkbit.STATUS_PANIC {
m.errList = append(m.errList, path)
} else if stat == chkbit.STATUS_OK || stat == chkbit.STATUS_UPDATE || stat == chkbit.STATUS_NEW {
m.errList = append(m.errList, message)
} else if stat == chkbit.STATUS_OK || stat == chkbit.STATUS_UPDATE || stat == chkbit.STATUS_NEW || stat == chkbit.STATUS_UP_WARN_OLD {
m.total++
if stat == chkbit.STATUS_UPDATE {
if stat == chkbit.STATUS_UPDATE || stat == chkbit.STATUS_UP_WARN_OLD {
m.numUpd++
} else if stat == chkbit.STATUS_NEW {
m.numNew++
@ -99,7 +99,7 @@ func (m *Main) logStatus(stat chkbit.Status, path string) bool {
}
if m.logVerbose || stat != chkbit.STATUS_OK && stat != chkbit.STATUS_IGNORE {
m.log(stat.String() + " " + path)
m.log(stat.String() + " " + message)
}
if m.verbose || !stat.IsVerbose() {
@ -107,7 +107,7 @@ func (m *Main) logStatus(stat chkbit.Status, path string) bool {
if stat.IsErrorOrWarning() {
col = termAlertFG
}
lterm.Printline(col, stat.String(), " ", path, lterm.Reset)
lterm.Printline(col, stat.String(), " ", message, lterm.Reset)
return true
}
}

View File

@ -125,7 +125,6 @@ func (i *Index) checkFix(force bool) {
if a, ok := i.cur[name]; !ok {
i.logFile(STATUS_NEW, name)
i.setMod(true)
continue
} else {
amod := int64(a.ModTime)
bmod := int64(b.ModTime)
@ -148,7 +147,7 @@ func (i *Index) checkFix(force bool) {
i.logFile(STATUS_UPDATE, name)
i.setMod(true)
} else if amod > bmod {
i.logFile(STATUS_WARN_OLD, name)
i.logFile(STATUS_UP_WARN_OLD, name)
i.setMod(true)
}
}

View File

@ -1,13 +1,14 @@
#!/bin/bash
export TZ='UTC'
root="/tmp/chkbit"
test_dir="/tmp/chkbit"
go run scripts/run_test_prep.go
cd $root/root
mv $root/root/people $root/people
cd $test_dir/root
mv $test_dir/root/people $test_dir/people
ln -s ../people people
ln -s ../../people/face/office-door.pdf day/friend/office-door.pdf
find -L -type f | wc -l

View File

@ -4,10 +4,10 @@ set -e
export TZ='UTC'
script_dir=$(dirname "$(realpath "$0")")
base_dir=$(dirname "$script_dir")
#dir=$(realpath "$script_dir/../testdata/run_test")
root="/tmp/chkbit/root"
test_dir="/tmp/chkbit"
function chkbit() { "$base_dir/chkbit" "$@"; }
if [[ ! -d $root ]]; then
if [[ ! -d $test_dir ]]; then
echo "must run run_test_prep first"
exit 1
fi
@ -15,7 +15,32 @@ fi
# setup
$script_dir/build
cd $test_dir
"$base_dir/chkbit" -u /tmp/chkbit/root
chkbit -u root
# todo: validate (300 files, 1 symlink dir followed, 1 symlink file ignored)
echo "- test damage"
rm -rf $test_dir/test_dmg
mkdir $test_dir/test_dmg
cd $test_dir/test_dmg
echo "-- create test and set the modified time"
echo foo1 > test; touch -t 201501010001 test
# says new:
chkbit -u .
echo "-- update test & old modified (expect 'old')"
echo foo2 > test; touch -t 201501010000 test
chkbit -u .
echo "-- update test & new modified (expect 'upd')"
echo foo3 > test; touch -t 201501010002 test
chkbit -u .
echo "-- Now update test with the same modified to simulate damage (expect DMG)"
echo foo4 > test; touch -t 201501010002 test
chkbit -u .

View File

@ -4,14 +4,14 @@ type Status string
const (
STATUS_PANIC Status = "EXC"
STATUS_ERR_DMG Status = "DMG"
STATUS_ERR_IDX Status = "EIX"
STATUS_WARN_OLD Status = "old"
STATUS_NEW Status = "new"
STATUS_ERR_DMG Status = "DMG"
STATUS_UPDATE_INDEX Status = "iup"
STATUS_UP_WARN_OLD Status = "old"
STATUS_UPDATE Status = "upd"
STATUS_NEW Status = "new"
STATUS_OK Status = "ok "
STATUS_IGNORE Status = "ign"
STATUS_UPDATE_INDEX Status = "iup"
)
func (s Status) String() string {
@ -19,7 +19,7 @@ func (s Status) String() string {
}
func (s Status) IsErrorOrWarning() bool {
return s == STATUS_PANIC || s == STATUS_ERR_DMG || s == STATUS_ERR_IDX || s == STATUS_WARN_OLD
return s == STATUS_PANIC || s == STATUS_ERR_DMG || s == STATUS_ERR_IDX || s == STATUS_UP_WARN_OLD
}
func (s Status) IsVerbose() bool {