mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Don't allow '/' in distribution name, auto-replace '/' with '-' while guessing. #110
This commit is contained in:
@@ -168,6 +168,9 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
|
||||
if distribution == "" || component == "" {
|
||||
rootDistributions, rootComponents := walkUpTree(source, collectionFactory)
|
||||
if distribution == "" {
|
||||
for i := range rootDistributions {
|
||||
rootDistributions[i] = strings.Replace(rootDistributions[i], "/", "-", -1)
|
||||
}
|
||||
discoveredDistributions = append(discoveredDistributions, rootDistributions...)
|
||||
}
|
||||
if component == "" {
|
||||
@@ -227,6 +230,10 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Index(distribution, "/") != -1 {
|
||||
return nil, fmt.Errorf("invalid distribution %s, '/' is not allowed", distribution)
|
||||
}
|
||||
|
||||
result.Distribution = distribution
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -167,6 +167,9 @@ func (s *PublishedRepoSuite) TestNewPublishedRepo(c *C) {
|
||||
|
||||
_, err := NewPublishedRepo("", ".", "a", nil, []string{"main", "main"}, []interface{}{s.snapshot, s.snapshot2}, s.factory)
|
||||
c.Check(err, ErrorMatches, "duplicate component name: main")
|
||||
|
||||
_, err = NewPublishedRepo("", ".", "wheezy/updates", nil, []string{"main"}, []interface{}{s.snapshot}, s.factory)
|
||||
c.Check(err, ErrorMatches, "invalid distribution wheezy/updates, '/' is not allowed")
|
||||
}
|
||||
|
||||
func (s *PublishedRepoSuite) TestPrefixNormalization(c *C) {
|
||||
@@ -267,6 +270,13 @@ func (s *PublishedRepoSuite) TestDistributionComponentGuessing(c *C) {
|
||||
c.Check(repo.Distribution, Equals, "precise")
|
||||
c.Check(repo.Components(), DeepEquals, []string{"contrib"})
|
||||
|
||||
s.localRepo.DefaultDistribution = "precise/updates"
|
||||
|
||||
repo, err = NewPublishedRepo("", "ppa", "", nil, []string{""}, []interface{}{s.localRepo}, s.factory)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(repo.Distribution, Equals, "precise-updates")
|
||||
c.Check(repo.Components(), DeepEquals, []string{"contrib"})
|
||||
|
||||
repo, err = NewPublishedRepo("", "ppa", "", nil, []string{"", "contrib"}, []interface{}{s.snapshot, s.snapshot2}, s.factory)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(repo.Distribution, Equals, "squeeze")
|
||||
|
||||
Reference in New Issue
Block a user