fix status
This commit is contained in:
parent
24b3a88576
commit
6f454f1836
@ -80,18 +80,18 @@ func (m *Main) log(text string) {
|
|||||||
m.logger.Println(time.Now().UTC().Format("2006-01-02 15:04:05"), text)
|
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 {
|
if stat == chkbit.STATUS_UPDATE_INDEX {
|
||||||
m.numIdxUpd++
|
m.numIdxUpd++
|
||||||
} else {
|
} else {
|
||||||
if stat == chkbit.STATUS_ERR_DMG {
|
if stat == chkbit.STATUS_ERR_DMG {
|
||||||
m.total++
|
m.total++
|
||||||
m.dmgList = append(m.dmgList, path)
|
m.dmgList = append(m.dmgList, message)
|
||||||
} else if stat == chkbit.STATUS_PANIC {
|
} else if stat == chkbit.STATUS_PANIC {
|
||||||
m.errList = append(m.errList, path)
|
m.errList = append(m.errList, message)
|
||||||
} else if stat == chkbit.STATUS_OK || stat == chkbit.STATUS_UPDATE || stat == chkbit.STATUS_NEW {
|
} else if stat == chkbit.STATUS_OK || stat == chkbit.STATUS_UPDATE || stat == chkbit.STATUS_NEW || stat == chkbit.STATUS_UP_WARN_OLD {
|
||||||
m.total++
|
m.total++
|
||||||
if stat == chkbit.STATUS_UPDATE {
|
if stat == chkbit.STATUS_UPDATE || stat == chkbit.STATUS_UP_WARN_OLD {
|
||||||
m.numUpd++
|
m.numUpd++
|
||||||
} else if stat == chkbit.STATUS_NEW {
|
} else if stat == chkbit.STATUS_NEW {
|
||||||
m.numNew++
|
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 {
|
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() {
|
if m.verbose || !stat.IsVerbose() {
|
||||||
@ -107,7 +107,7 @@ func (m *Main) logStatus(stat chkbit.Status, path string) bool {
|
|||||||
if stat.IsErrorOrWarning() {
|
if stat.IsErrorOrWarning() {
|
||||||
col = termAlertFG
|
col = termAlertFG
|
||||||
}
|
}
|
||||||
lterm.Printline(col, stat.String(), " ", path, lterm.Reset)
|
lterm.Printline(col, stat.String(), " ", message, lterm.Reset)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
index.go
3
index.go
@ -125,7 +125,6 @@ func (i *Index) checkFix(force bool) {
|
|||||||
if a, ok := i.cur[name]; !ok {
|
if a, ok := i.cur[name]; !ok {
|
||||||
i.logFile(STATUS_NEW, name)
|
i.logFile(STATUS_NEW, name)
|
||||||
i.setMod(true)
|
i.setMod(true)
|
||||||
continue
|
|
||||||
} else {
|
} else {
|
||||||
amod := int64(a.ModTime)
|
amod := int64(a.ModTime)
|
||||||
bmod := int64(b.ModTime)
|
bmod := int64(b.ModTime)
|
||||||
@ -148,7 +147,7 @@ func (i *Index) checkFix(force bool) {
|
|||||||
i.logFile(STATUS_UPDATE, name)
|
i.logFile(STATUS_UPDATE, name)
|
||||||
i.setMod(true)
|
i.setMod(true)
|
||||||
} else if amod > bmod {
|
} else if amod > bmod {
|
||||||
i.logFile(STATUS_WARN_OLD, name)
|
i.logFile(STATUS_UP_WARN_OLD, name)
|
||||||
i.setMod(true)
|
i.setMod(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export TZ='UTC'
|
export TZ='UTC'
|
||||||
root="/tmp/chkbit"
|
test_dir="/tmp/chkbit"
|
||||||
|
|
||||||
go run scripts/run_test_prep.go
|
go run scripts/run_test_prep.go
|
||||||
|
|
||||||
cd $root/root
|
cd $test_dir/root
|
||||||
mv $root/root/people $root/people
|
mv $test_dir/root/people $test_dir/people
|
||||||
ln -s ../people people
|
ln -s ../people people
|
||||||
ln -s ../../people/face/office-door.pdf day/friend/office-door.pdf
|
ln -s ../../people/face/office-door.pdf day/friend/office-door.pdf
|
||||||
|
|
||||||
|
|
||||||
find -L -type f | wc -l
|
find -L -type f | wc -l
|
||||||
|
@ -4,10 +4,10 @@ set -e
|
|||||||
export TZ='UTC'
|
export TZ='UTC'
|
||||||
script_dir=$(dirname "$(realpath "$0")")
|
script_dir=$(dirname "$(realpath "$0")")
|
||||||
base_dir=$(dirname "$script_dir")
|
base_dir=$(dirname "$script_dir")
|
||||||
#dir=$(realpath "$script_dir/../testdata/run_test")
|
test_dir="/tmp/chkbit"
|
||||||
root="/tmp/chkbit/root"
|
function chkbit() { "$base_dir/chkbit" "$@"; }
|
||||||
|
|
||||||
if [[ ! -d $root ]]; then
|
if [[ ! -d $test_dir ]]; then
|
||||||
echo "must run run_test_prep first"
|
echo "must run run_test_prep first"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -15,7 +15,32 @@ fi
|
|||||||
# setup
|
# setup
|
||||||
|
|
||||||
$script_dir/build
|
$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)
|
# 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 .
|
||||||
|
|
||||||
|
10
status.go
10
status.go
@ -4,14 +4,14 @@ type Status string
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
STATUS_PANIC Status = "EXC"
|
STATUS_PANIC Status = "EXC"
|
||||||
STATUS_ERR_DMG Status = "DMG"
|
|
||||||
STATUS_ERR_IDX Status = "EIX"
|
STATUS_ERR_IDX Status = "EIX"
|
||||||
STATUS_WARN_OLD Status = "old"
|
STATUS_ERR_DMG Status = "DMG"
|
||||||
STATUS_NEW Status = "new"
|
STATUS_UPDATE_INDEX Status = "iup"
|
||||||
|
STATUS_UP_WARN_OLD Status = "old"
|
||||||
STATUS_UPDATE Status = "upd"
|
STATUS_UPDATE Status = "upd"
|
||||||
|
STATUS_NEW Status = "new"
|
||||||
STATUS_OK Status = "ok "
|
STATUS_OK Status = "ok "
|
||||||
STATUS_IGNORE Status = "ign"
|
STATUS_IGNORE Status = "ign"
|
||||||
STATUS_UPDATE_INDEX Status = "iup"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Status) String() string {
|
func (s Status) String() string {
|
||||||
@ -19,7 +19,7 @@ func (s Status) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Status) IsErrorOrWarning() bool {
|
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 {
|
func (s Status) IsVerbose() bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user