Fix race in fatal exit & context shutdown.

This commit is contained in:
Andrey Smirnov
2014-03-04 18:26:19 +04:00
parent e59c327a7c
commit 1902f38e6b
9 changed files with 34 additions and 2 deletions

10
main.go
View File

@@ -9,9 +9,11 @@ import (
"path/filepath"
)
var returnCode = 0
func fatal(err error) {
fmt.Printf("ERROR: %s\n", err)
os.Exit(1)
returnCode = 1
}
func loadConfig(command *commander.Command) error {
@@ -50,26 +52,32 @@ func loadConfig(command *commander.Command) error {
}
func main() {
defer func() { os.Exit(returnCode) }()
command := cmd.RootCommand()
err := command.Flag.Parse(os.Args[1:])
if err != nil {
fatal(err)
return
}
err = loadConfig(command)
if err != nil {
fatal(err)
return
}
err = cmd.InitContext(command)
if err != nil {
fatal(err)
return
}
defer cmd.ShutdownContext()
err = command.Dispatch(command.Flag.Args())
if err != nil {
fatal(err)
return
}
}

View File

@@ -1 +1,3 @@
ERROR: unable to determine list of architectures, please specify explicitly
Loading packages...

View File

@@ -1 +1,3 @@
ERROR: unable to copy: unable to parse dependency: pyspi >> 0.6.1-1.3)
Loading packages...

View File

@@ -1,2 +1,3 @@
Loading packages...
ERROR: unable to import: unable to parse dependency: pyspi >> 0.6.1-1.3)
Loading packages...

View File

@@ -1 +1,3 @@
ERROR: unable to determine list of architectures, please specify explicitly
Loading packages...

View File

@@ -1 +1,3 @@
ERROR: unable to move: unable to parse dependency: pyspi >> 0.6.1-1.3)
Loading packages...

View File

@@ -83,6 +83,9 @@ class ImportRepo5Test(BaseTest):
runCmd = "aptly repo import wheezy-contrib repo1 'pyspi >> 0.6.1-1.3)'"
expectedCode = 1
def output_processor(self, output):
return "\n".join(sorted(output.split("\n")))
class ImportRepo6Test(BaseTest):
"""

View File

@@ -53,6 +53,9 @@ class CopyRepo3Test(BaseTest):
runCmd = "aptly repo copy -with-deps repo1 repo2 'pyspi (>> 0.6.1-1.3)' libboost-program-options-dev_1.49.0.1_i386"
expectedCode = 1
def output_processor(self, output):
return "\n".join(sorted(output.split("\n")))
class CopyRepo4Test(BaseTest):
"""
@@ -86,6 +89,9 @@ class CopyRepo5Test(BaseTest):
runCmd = "aptly repo copy repo1 repo2 'pyspi >> 0.6.1-1.3)'"
expectedCode = 1
def output_processor(self, output):
return "\n".join(sorted(output.split("\n")))
class CopyRepo6Test(BaseTest):
"""

View File

@@ -53,6 +53,9 @@ class MoveRepo3Test(BaseTest):
runCmd = "aptly repo move -with-deps repo1 repo2 'pyspi (>> 0.6.1-1.3)' libboost-program-options-dev_1.49.0.1_i386"
expectedCode = 1
def output_processor(self, output):
return "\n".join(sorted(output.split("\n")))
class MoveRepo4Test(BaseTest):
"""
@@ -86,6 +89,9 @@ class MoveRepo5Test(BaseTest):
runCmd = "aptly repo move repo1 repo2 'pyspi >> 0.6.1-1.3)'"
expectedCode = 1
def output_processor(self, output):
return "\n".join(sorted(output.split("\n")))
class MoveRepo6Test(BaseTest):
"""