CollectPackageFiles walks filesystem collecting all candidates for package files
(locations []string, reporter aptly.ResultReporter)
| 15 | |
| 16 | // CollectPackageFiles walks filesystem collecting all candidates for package files |
| 17 | func CollectPackageFiles(locations []string, reporter aptly.ResultReporter) (packageFiles, otherFiles, failedFiles []string) { |
| 18 | packageFilesLock := &sync.Mutex{} |
| 19 | otherFilesLock := &sync.Mutex{} |
| 20 | |
| 21 | for _, location := range locations { |
| 22 | info, err2 := os.Stat(location) |
| 23 | if err2 != nil { |
| 24 | reporter.Warning("Unable to process %s: %s", location, err2) |
| 25 | failedFiles = append(failedFiles, location) |
| 26 | continue |
| 27 | } |
| 28 | if info.IsDir() { |
| 29 | err2 = walker.Walk(location, func(path string, info os.FileInfo) error { |
| 30 | if info.IsDir() { |
| 31 | return nil |
| 32 | } |
| 33 | |
| 34 | if strings.HasSuffix(info.Name(), ".deb") || strings.HasSuffix(info.Name(), ".udeb") || |
| 35 | strings.HasSuffix(info.Name(), ".dsc") || strings.HasSuffix(info.Name(), ".ddeb") { |
| 36 | packageFilesLock.Lock() |
| 37 | defer packageFilesLock.Unlock() |
| 38 | packageFiles = append(packageFiles, path) |
| 39 | } else if strings.HasSuffix(info.Name(), ".buildinfo") { |
| 40 | otherFilesLock.Lock() |
| 41 | defer otherFilesLock.Unlock() |
| 42 | otherFiles = append(otherFiles, path) |
| 43 | } |
| 44 | |
| 45 | return nil |
| 46 | }) |
| 47 | |
| 48 | if err2 != nil { |
| 49 | reporter.Warning("Unable to process %s: %s", location, err2) |
| 50 | failedFiles = append(failedFiles, location) |
| 51 | continue |
| 52 | } |
| 53 | } else { |
| 54 | if strings.HasSuffix(info.Name(), ".deb") || strings.HasSuffix(info.Name(), ".udeb") || |
| 55 | strings.HasSuffix(info.Name(), ".dsc") || strings.HasSuffix(info.Name(), ".ddeb") { |
| 56 | packageFiles = append(packageFiles, location) |
| 57 | } else if strings.HasSuffix(info.Name(), ".buildinfo") { |
| 58 | otherFiles = append(otherFiles, location) |
| 59 | } else { |
| 60 | reporter.Warning("Unknown file extension: %s", location) |
| 61 | failedFiles = append(failedFiles, location) |
| 62 | continue |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | sort.Strings(packageFiles) |
| 68 | |
| 69 | return |
| 70 | } |
| 71 | |
| 72 | // ImportPackageFiles imports files into local repository |
| 73 | func ImportPackageFiles(list *PackageList, packageFiles []string, forceReplace bool, verifier pgp.Verifier, |
no test coverage detected