Skip to content

Commit 50807f7

Browse files
committed
ideomatic
1 parent 83515ba commit 50807f7

File tree

6 files changed

+45
-45
lines changed

6 files changed

+45
-45
lines changed

cmd/chkbit/main.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (m *Main) logInfo(col, text string) {
124124
}
125125

126126
func (m *Main) logError(text string) {
127-
text = chkbit.STATUS_PANIC.String() + " " + text
127+
text = chkbit.StatusPanic.String() + " " + text
128128

129129
if m.progress == Fancy {
130130
lterm.Write(termAlertFG)
@@ -148,13 +148,13 @@ func (m *Main) printError(text string) {
148148
}
149149

150150
func (m *Main) logStatus(stat chkbit.Status, message string) bool {
151-
if stat == chkbit.STATUS_UPDATE_INDEX {
151+
if stat == chkbit.StatusUpdateIndex {
152152
return false
153153
}
154154

155-
if stat == chkbit.STATUS_ERR_DMG {
155+
if stat == chkbit.StatusErrorDamage {
156156
m.dmgList = append(m.dmgList, message)
157-
} else if stat == chkbit.STATUS_PANIC {
157+
} else if stat == chkbit.StatusPanic {
158158
m.errList = append(m.errList, message)
159159
}
160160

@@ -164,7 +164,7 @@ func (m *Main) logStatus(stat chkbit.Status, message string) bool {
164164

165165
if m.verbose || !stat.IsVerbose() {
166166

167-
if m.progress == Quiet && stat == chkbit.STATUS_INFO {
167+
if m.progress == Quiet && stat == chkbit.StatusInfo {
168168
return false
169169
}
170170

@@ -259,11 +259,11 @@ func (m *Main) process(cmd Command, cli CLI) (bool, error) {
259259

260260
if cli.Db {
261261
var root string
262-
root, pathList, err = m.context.UseIndexDb(pathList)
262+
root, pathList, err = m.context.UseStoreDb(pathList)
263263
if err == nil {
264264
// pathList is relative to root
265265
err = os.Chdir(root)
266-
m.logInfo("", "Using indexdb in "+root)
266+
m.logInfo("", "Using store-db in "+root)
267267
}
268268
if err != nil {
269269
return false, err

context.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,32 @@ func (context *Context) log(stat Status, message string) {
6868
context.mutex.Lock()
6969
defer context.mutex.Unlock()
7070
switch stat {
71-
case STATUS_ERR_DMG:
71+
case StatusErrorDamage:
7272
context.NumTotal++
73-
case STATUS_UPDATE_INDEX:
73+
case StatusUpdateIndex:
7474
context.NumIdxUpd++
75-
case STATUS_UP_WARN_OLD:
75+
case StatusUpdateWarnOld:
7676
context.NumTotal++
7777
context.NumUpd++
78-
case STATUS_UPDATE:
78+
case StatusUpdate:
7979
context.NumTotal++
8080
context.NumUpd++
81-
case STATUS_NEW:
81+
case StatusNew:
8282
context.NumTotal++
8383
context.NumNew++
84-
case STATUS_OK:
84+
case StatusOK:
8585
if !context.AddOnly {
8686
context.NumTotal++
8787
}
88-
case STATUS_MISSING:
88+
case StatusMissing:
8989
context.NumDel++
9090
}
9191

9292
context.LogQueue <- &LogEvent{stat, message}
9393
}
9494

9595
func (context *Context) logErr(path string, err error) {
96-
context.log(STATUS_PANIC, path+": "+err.Error())
96+
context.log(StatusPanic, path+": "+err.Error())
9797
}
9898

9999
func (context *Context) perfMonFiles(numFiles int64) {
@@ -152,7 +152,7 @@ func (context *Context) Process(pathList []string) {
152152
if updated, err := context.store.Finish(); err != nil {
153153
context.logErr("index", err)
154154
} else if updated {
155-
context.log(STATUS_INFO, "The index db was updated")
155+
context.log(StatusInfo, "The index db was updated")
156156
}
157157
context.LogQueue <- nil
158158
}
@@ -193,7 +193,7 @@ func (context *Context) scanDir(root string, parentIgnore *Ignore) {
193193
if !ignore.shouldIgnore(file.Name()) {
194194
dirList = append(dirList, file.Name())
195195
} else {
196-
context.log(STATUS_IGNORE, file.Name()+"/")
196+
context.log(StatusIgnore, file.Name()+"/")
197197
}
198198
} else if file.Type().IsRegular() {
199199
filesToIndex = append(filesToIndex, file.Name())
@@ -209,7 +209,7 @@ func (context *Context) scanDir(root string, parentIgnore *Ignore) {
209209
}
210210
}
211211

212-
func (context *Context) UseIndexDb(pathList []string) (root string, relativePathList []string, err error) {
212+
func (context *Context) UseStoreDb(pathList []string) (root string, relativePathList []string, err error) {
213213

214214
if len(pathList) == 0 {
215215
return "", nil, errors.New("missing path(s)")
@@ -225,7 +225,7 @@ func (context *Context) UseIndexDb(pathList []string) (root string, relativePath
225225

226226
// below root?
227227
if !strings.HasPrefix(path, root) {
228-
return "", nil, fmt.Errorf("path %s is not below the indexdb in %s", path, root)
228+
return "", nil, fmt.Errorf("path %s is not below the store-db in %s", path, root)
229229
}
230230

231231
relativePath, err := filepath.Rel(root, path)

index.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (i *Index) getIndexFilepath() string {
7474
}
7575

7676
func (i *Index) logFilePanic(name string, message string) {
77-
i.context.log(STATUS_PANIC, filepath.Join(i.path, name)+": "+message)
77+
i.context.log(StatusPanic, filepath.Join(i.path, name)+": "+message)
7878
}
7979

8080
func (i *Index) logFile(stat Status, name string) {
@@ -89,7 +89,7 @@ func (i *Index) calcHashes(ignore *Ignore) {
8989
for _, name := range i.files {
9090
if ignore.shouldIgnore(name) {
9191
if !ignore.context.isChkbitFile(name) {
92-
i.logFile(STATUS_IGNORE, name)
92+
i.logFile(StatusIgnore, name)
9393
}
9494
continue
9595
}
@@ -135,40 +135,40 @@ func (i *Index) calcHashes(ignore *Ignore) {
135135
func (i *Index) showIgnoredOnly(ignore *Ignore) {
136136
for _, name := range i.files {
137137
if ignore.shouldIgnore(name) {
138-
i.logFile(STATUS_IGNORE, name)
138+
i.logFile(StatusIgnore, name)
139139
}
140140
}
141141
}
142142

143143
func (i *Index) checkFix(forceUpdateDmg bool) {
144144
for name, b := range i.new {
145145
if a, ok := i.cur[name]; !ok {
146-
i.logFile(STATUS_NEW, name)
146+
i.logFile(StatusNew, name)
147147
i.modified = true
148148
} else {
149149
amod := int64(a.ModTime)
150150
bmod := int64(b.ModTime)
151151
if a.Hash != nil && b.Hash != nil && *a.Hash == *b.Hash {
152-
i.logFile(STATUS_OK, name)
152+
i.logFile(StatusOK, name)
153153
if amod != bmod {
154154
i.modified = true
155155
}
156156
continue
157157
}
158158

159159
if amod == bmod {
160-
i.logFile(STATUS_ERR_DMG, name)
160+
i.logFile(StatusErrorDamage, name)
161161
if !forceUpdateDmg {
162162
// keep DMG entry
163163
i.new[name] = a
164164
} else {
165165
i.modified = true
166166
}
167167
} else if amod < bmod {
168-
i.logFile(STATUS_UPDATE, name)
168+
i.logFile(StatusUpdate, name)
169169
i.modified = true
170170
} else if amod > bmod {
171-
i.logFile(STATUS_UP_WARN_OLD, name)
171+
i.logFile(StatusUpdateWarnOld, name)
172172
i.modified = true
173173
}
174174
}
@@ -178,7 +178,7 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
178178
if _, ok := i.new[name]; !ok {
179179
i.modified = true
180180
if i.context.ShowMissing {
181-
i.logFile(STATUS_MISSING, name)
181+
i.logFile(StatusMissing, name)
182182
}
183183
}
184184
}
@@ -192,7 +192,7 @@ func (i *Index) checkFix(forceUpdateDmg bool) {
192192
if !m[name] {
193193
i.modified = true
194194
if i.context.ShowMissing {
195-
i.logDir(STATUS_MISSING, name+"/")
195+
i.logDir(StatusMissing, name+"/")
196196
}
197197
}
198198
}
@@ -284,7 +284,7 @@ func (i *Index) load() error {
284284
}
285285
if data.IdxHash != hashMd5(text) {
286286
i.modified = true
287-
i.logFile(STATUS_ERR_IDX, i.getIndexFilepath())
287+
i.logFile(StatusErrorIdx, i.getIndexFilepath())
288288
}
289289
} else {
290290
var data1 indexFile1

status.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ package chkbit
33
type Status string
44

55
const (
6-
STATUS_PANIC Status = "EXC"
7-
STATUS_ERR_IDX Status = "ERX"
8-
STATUS_ERR_DMG Status = "DMG"
9-
STATUS_UP_WARN_OLD Status = "old"
10-
STATUS_UPDATE Status = "upd"
11-
STATUS_NEW Status = "new"
12-
STATUS_OK Status = "ok "
13-
STATUS_IGNORE Status = "ign"
14-
STATUS_MISSING Status = "del"
15-
STATUS_INFO Status = "msg"
6+
StatusPanic Status = "EXC"
7+
StatusErrorIdx Status = "ERX"
8+
StatusErrorDamage Status = "DMG"
9+
StatusUpdateWarnOld Status = "old"
10+
StatusUpdate Status = "upd"
11+
StatusNew Status = "new"
12+
StatusOK Status = "ok "
13+
StatusIgnore Status = "ign"
14+
StatusMissing Status = "del"
15+
StatusInfo Status = "msg"
1616

1717
// internal
18-
STATUS_UPDATE_INDEX Status = "xup"
18+
StatusUpdateIndex Status = "xup"
1919
)
2020

2121
func (s Status) String() string {
2222
return (string)(s)
2323
}
2424

2525
func (s Status) IsErrorOrWarning() bool {
26-
return s == STATUS_PANIC || s == STATUS_ERR_DMG || s == STATUS_ERR_IDX || s == STATUS_UP_WARN_OLD
26+
return s == StatusPanic || s == StatusErrorDamage || s == StatusErrorIdx || s == StatusUpdateWarnOld
2727
}
2828

2929
func (s Status) IsVerbose() bool {
30-
return s == STATUS_OK || s == STATUS_IGNORE
30+
return s == StatusOK || s == StatusIgnore
3131
}
3232

3333
type LogEvent struct {

store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (s *store) UseDb(path string, indexName string, refresh bool) {
5050
}
5151

5252
func (s *store) logErr(message string) {
53-
s.logQueue <- &LogEvent{STATUS_PANIC, "index-db: " + message}
53+
s.logQueue <- &LogEvent{StatusPanic, "index-db: " + message}
5454
}
5555

5656
func (s *store) Open(readOnly bool, numWorkers int) error {

worker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (context *Context) runWorker(id int) {
3030
if changed, err := index.save(); err != nil {
3131
context.logErr(item.path, err)
3232
} else if changed {
33-
context.log(STATUS_UPDATE_INDEX, "")
33+
context.log(StatusUpdateIndex, "")
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)