Skip to content

Commit f9c8c7e

Browse files
committed
Code refactoring
1 parent 4c3ea3a commit f9c8c7e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

cli/cli.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,11 @@ var repoNamePattern = `[0-9a-zA-Z_\-]+`
228228
// configs contains repositories configs
229229
var configs map[string]*knf.Config
230230

231-
// isCanceled is a flag for marking that user want to cancel app execution
231+
// isCanceled is an atomic flag indicating the user canceled execution (SIGINT/SIGTERM)
232232
var isCanceled atomic.Bool
233233

234-
// isCancelProtected is a flag for marking current execution from canceling
234+
// isCancelProtected is an atomic flag indicating critical sections that should not
235+
// be interrupted
235236
var isCancelProtected atomic.Bool
236237

237238
// rawOutput is raw output flag
@@ -548,7 +549,7 @@ func sigHandler() {
548549
shutdown(EC_ERROR)
549550
}
550551

551-
isCanceled.CompareAndSwap(false, true)
552+
isCanceled.Store(true)
552553
}
553554

554555
// shutdown cleans temporary data and exits from CLI

cli/cmd_resign.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ func resignRepoPackages(ctx *context, key *sign.Key, r *repo.SubRepository) bool
119119
pb := progress.New(int64(len(files)), "Re-signing")
120120
pb.Start()
121121

122+
isCancelProtected.Store(true)
123+
defer isCancelProtected.Store(false)
124+
122125
for _, file := range files {
123-
isCancelProtected.Store(true)
124126

125127
filePath := r.GetFullPackagePath(file)
126128
fileName := path.Base(filePath)
@@ -148,8 +150,6 @@ func resignRepoPackages(ctx *context, key *sign.Key, r *repo.SubRepository) bool
148150
pb.Finish()
149151
return false
150152
}
151-
152-
isCancelProtected.Store(false)
153153
}
154154

155155
pb.Finish()

cli/common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ func warmUpCache(r *repo.Repository) {
254254
}
255255

256256
isCancelProtected.Store(true)
257+
defer isCancelProtected.Store(false)
257258

258259
if warmupTesting {
259260
fmtc.If(!rawOutput && !options.GetB(OPT_PAGER)).TPrintf("{s-}Warming up testing repository cache (it can take a while)…{!}")
@@ -271,8 +272,6 @@ func warmUpCache(r *repo.Repository) {
271272
}
272273

273274
fmtc.If(!rawOutput && !options.GetB(OPT_PAGER)).TPrintf("")
274-
275-
isCancelProtected.Store(false)
276275
}
277276

278277
// checkForLock check for lock file

0 commit comments

Comments
 (0)