mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-19 19:28:22 +00:00
aptly repo add now exists with non-zero exit code if some files fail to add. #54
This commit is contained in:
@@ -41,11 +41,13 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
|
||||
packageFiles := []string{}
|
||||
failedFiles := []string{}
|
||||
|
||||
for _, location := range args[1:] {
|
||||
info, err2 := os.Stat(location)
|
||||
if err2 != nil {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to process %s: %s@|", location, err2)
|
||||
failedFiles = append(failedFiles, location)
|
||||
continue
|
||||
}
|
||||
if info.IsDir() {
|
||||
@@ -68,6 +70,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
packageFiles = append(packageFiles, location)
|
||||
} else {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unknwon file extenstion: %s@|", location)
|
||||
failedFiles = append(failedFiles, location)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -100,6 +103,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
if err != nil {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to read file %s: %s@|", file, err)
|
||||
failedFiles = append(failedFiles, file)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -118,6 +122,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
err = context.PackagePool().Import(file, checksums.MD5)
|
||||
if err != nil {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to import file %s into pool: %s@|", file, err)
|
||||
failedFiles = append(failedFiles, file)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -132,6 +137,7 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
err = context.PackagePool().Import(sourceFile, f.Checksums.MD5)
|
||||
if err != nil {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to import file %s into pool: %s@|", sourceFile, err)
|
||||
failedFiles = append(failedFiles, file)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -145,12 +151,14 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
err = context.CollectionFactory().PackageCollection().Update(p)
|
||||
if err != nil {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to save package %s: %s@|", p, err)
|
||||
failedFiles = append(failedFiles, file)
|
||||
continue
|
||||
}
|
||||
|
||||
err = list.Add(p)
|
||||
if err != nil {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Unable to add package to repo %s: %s@|", p, err)
|
||||
failedFiles = append(failedFiles, file)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -176,6 +184,15 @@ func aptlyRepoAdd(cmd *commander.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(failedFiles) > 0 {
|
||||
context.Progress().ColoredPrintf("@y[!]@| @!Some files were skipped due to errors:@|")
|
||||
for _, file := range failedFiles {
|
||||
context.Progress().ColoredPrintf(" %s", file)
|
||||
}
|
||||
|
||||
return fmt.Errorf("Some files failed to be added")
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
Loading packages...
|
||||
[!] Unable to import file /02/03/pyspi_0.6.1-1.3.diff.gz into pool: open /02/03/pyspi_0.6.1-1.3.diff.gz: no such file or directory
|
||||
[!] Some files were skipped due to errors:
|
||||
/02/03/pyspi_0.6.1-1.3.dsc
|
||||
ERROR: Some files failed to be added
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
Loading packages...
|
||||
[!] Unable to process no-such-file: stat no-such-file: no such file or directory
|
||||
[!] Some files were skipped due to errors:
|
||||
no-such-file
|
||||
ERROR: Some files failed to be added
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
Loading packages...
|
||||
[!] Unable to save package pyspi_0.6.1-1.3_source: unable to save: pyspi_0.6.1-1.3_source, conflict with existing packge
|
||||
[!] Unable to save package pyspi_0.6.1-1.3_source: unable to save: pyspi_0.6.1-1.3_source, conflict with existing package
|
||||
[!] Some files were skipped due to errors:
|
||||
/Users/smira/Documents/go/src/github.com/smira/aptly/system/t09_repo/AddRepo8Test/pyspi_0.6.1-1.3.conflict.dsc
|
||||
ERROR: Some files failed to be added
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
Loading packages...
|
||||
[!] Unable to import file /pyspi_0.6.1.orig.tar.gz into pool: unable to import into pool: file ${HOME}/.aptly/pool/de/f3/pyspi_0.6.1.orig.tar.gz already exists
|
||||
[!] Some files were skipped due to errors:
|
||||
/pyspi_0.6.1-1.3.dsc
|
||||
ERROR: Some files failed to be added
|
||||
|
||||
@@ -125,6 +125,7 @@ class AddRepo5Test(BaseTest):
|
||||
]
|
||||
runCmd = "aptly repo add repo5 "
|
||||
outputMatchPrepare = lambda self, s: s.replace(self.tempSrcDir, "")
|
||||
expectedCode = 1
|
||||
|
||||
def prepare(self):
|
||||
super(AddRepo5Test, self).prepare()
|
||||
@@ -154,6 +155,7 @@ class AddRepo6Test(BaseTest):
|
||||
"aptly repo create -comment=Repo6 -distribution=squeeze repo6",
|
||||
]
|
||||
runCmd = "aptly repo add repo6 no-such-file"
|
||||
expectedCode = 1
|
||||
|
||||
|
||||
class AddRepo7Test(BaseTest):
|
||||
@@ -173,6 +175,8 @@ class AddRepo8Test(BaseTest):
|
||||
"aptly repo add repo8 ${files}/pyspi_0.6.1-1.3.dsc",
|
||||
]
|
||||
runCmd = "aptly repo add repo8 ${testfiles}/pyspi_0.6.1-1.3.conflict.dsc"
|
||||
outputMatchPrepare = lambda self, s: s.replace(os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files"), "")
|
||||
expectedCode = 1
|
||||
|
||||
def check(self):
|
||||
self.check_output()
|
||||
@@ -187,8 +191,9 @@ class AddRepo9Test(BaseTest):
|
||||
"aptly repo create -comment=Repo9 -distribution=squeeze repo9",
|
||||
]
|
||||
runCmd = "aptly repo add repo9 ${files}/pyspi_0.6.1-1.3.dsc"
|
||||
outputMatchPrepare = lambda self, s: s.replace(os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files"), "")
|
||||
outputMatchPrepare = lambda self, s: s.replace(os.path.join(os.path.dirname(inspect.getsourcefile(self.__class__)), self.__class__.__name__), "").replace(os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "files"), "")
|
||||
gold_processor = BaseTest.expand_environ
|
||||
expectedCode = 1
|
||||
|
||||
def prepare(self):
|
||||
super(AddRepo9Test, self).prepare()
|
||||
|
||||
Reference in New Issue
Block a user