Ejemplo n.º 1
0
func (s *PublishedRepoSuite) SetUpTest(c *C) {
	s.SetUpPackages()

	s.db, _ = database.OpenDB(c.MkDir())
	s.factory = NewCollectionFactory(s.db)

	s.root = c.MkDir()
	s.publishedStorage = files.NewPublishedStorage(s.root)
	s.root2 = c.MkDir()
	s.publishedStorage2 = files.NewPublishedStorage(s.root2)
	s.provider = &FakeStorageProvider{map[string]aptly.PublishedStorage{
		"":            s.publishedStorage,
		"files:other": s.publishedStorage2}}
	s.packagePool = files.NewPackagePool(s.root)

	repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false, false)
	repo.packageRefs = s.reflist
	s.factory.RemoteRepoCollection().Add(repo)

	s.localRepo = NewLocalRepo("local1", "comment1")
	s.localRepo.packageRefs = s.reflist
	s.factory.LocalRepoCollection().Add(s.localRepo)

	s.snapshot, _ = NewSnapshotFromRepository("snap", repo)
	s.factory.SnapshotCollection().Add(s.snapshot)

	s.snapshot2, _ = NewSnapshotFromRepository("snap", repo)
	s.factory.SnapshotCollection().Add(s.snapshot2)

	s.packageCollection = s.factory.PackageCollection()
	s.packageCollection.Update(s.p1)
	s.packageCollection.Update(s.p2)
	s.packageCollection.Update(s.p3)

	s.repo, _ = NewPublishedRepo("", "ppa", "squeeze", nil, []string{"main"}, []interface{}{s.snapshot}, s.factory)
	s.repo.SkipContents = true

	s.repo2, _ = NewPublishedRepo("", "ppa", "maverick", nil, []string{"main"}, []interface{}{s.localRepo}, s.factory)
	s.repo2.SkipContents = true

	s.repo3, _ = NewPublishedRepo("", "linux", "natty", nil, []string{"main", "contrib"}, []interface{}{s.snapshot, s.snapshot2}, s.factory)
	s.repo3.SkipContents = true

	s.repo4, _ = NewPublishedRepo("", "ppa", "maverick", []string{"source"}, []string{"main"}, []interface{}{s.localRepo}, s.factory)
	s.repo4.SkipContents = true

	s.repo5, _ = NewPublishedRepo("files:other", "ppa", "maverick", []string{"source"}, []string{"main"}, []interface{}{s.localRepo}, s.factory)
	s.repo5.SkipContents = true

	poolPath, _ := s.packagePool.Path(s.p1.Files()[0].Filename, s.p1.Files()[0].Checksums.MD5)
	err := os.MkdirAll(filepath.Dir(poolPath), 0755)
	f, err := os.Create(poolPath)
	c.Assert(err, IsNil)
	f.Close()
}
Ejemplo n.º 2
0
func (s *PublishedRepoSuite) SetUpTest(c *C) {
	s.SetUpPackages()

	s.db, _ = database.OpenDB(c.MkDir())

	s.root = c.MkDir()
	s.publishedStorage = files.NewPublishedStorage(s.root)
	s.packagePool = files.NewPackagePool(s.root)

	repo, _ := NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{}, false)
	repo.packageRefs = s.reflist

	s.snapshot, _ = NewSnapshotFromRepository("snap", repo)

	s.repo, _ = NewPublishedRepo("ppa", "squeeze", "main", nil, s.snapshot)

	s.packageCollection = NewPackageCollection(s.db)
	s.packageCollection.Update(s.p1)
	s.packageCollection.Update(s.p2)
	s.packageCollection.Update(s.p3)

	poolPath, _ := s.packagePool.Path(s.p1.Files()[0].Filename, s.p1.Files()[0].Checksums.MD5)
	err := os.MkdirAll(filepath.Dir(poolPath), 0755)
	f, err := os.Create(poolPath)
	c.Assert(err, IsNil)
	f.Close()
}
Ejemplo n.º 3
0
func (s *PublishedRepoRemoveSuite) SetUpTest(c *C) {
	s.db, _ = database.OpenDB(c.MkDir())

	s.snapshotCollection = NewSnapshotCollection(s.db)

	s.snap1 = NewSnapshotFromPackageList("snap1", []*Snapshot{}, NewPackageList(), "desc1")

	s.snapshotCollection.Add(s.snap1)

	s.repo1, _ = NewPublishedRepo("ppa", "anaconda", "main", []string{}, s.snap1)
	s.repo2, _ = NewPublishedRepo("", "anaconda", "main", []string{}, s.snap1)
	s.repo3, _ = NewPublishedRepo("ppa", "meduza", "main", []string{}, s.snap1)
	s.repo4, _ = NewPublishedRepo("ppa", "osminog", "contrib", []string{}, s.snap1)

	s.collection = NewPublishedRepoCollection(s.db)
	s.collection.Add(s.repo1)
	s.collection.Add(s.repo2)
	s.collection.Add(s.repo3)
	s.collection.Add(s.repo4)

	s.root = c.MkDir()
	s.publishedStorage = files.NewPublishedStorage(s.root)
	s.publishedStorage.MkDir("ppa/dists/anaconda")
	s.publishedStorage.MkDir("ppa/dists/meduza")
	s.publishedStorage.MkDir("ppa/dists/osminog")
	s.publishedStorage.MkDir("ppa/pool/main")
	s.publishedStorage.MkDir("ppa/pool/contrib")
	s.publishedStorage.MkDir("dists/anaconda")
	s.publishedStorage.MkDir("pool/main")
}
Ejemplo n.º 4
0
// PublishedStorage returns instance of PublishedStorage
func (context *AptlyContext) PublishedStorage() aptly.PublishedStorage {
	if context.publishedStorage == nil {
		context.publishedStorage = files.NewPublishedStorage(context.Config().RootDir)
	}

	return context.publishedStorage
}
Ejemplo n.º 5
0
// GetPublishedStorage returns instance of PublishedStorage
func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedStorage {
	publishedStorage, ok := context.publishedStorages[name]
	if !ok {
		if name == "" {
			publishedStorage = files.NewPublishedStorage(context.Config().RootDir)
		} else if strings.HasPrefix(name, "s3:") {
			params, ok := context.Config().S3PublishRoots[name[3:]]
			if !ok {
				Fatal(fmt.Errorf("published S3 storage %v not configured", name[3:]))
			}

			var err error
			publishedStorage, err = s3.NewPublishedStorage(params.AccessKeyID, params.SecretAccessKey,
				params.Region, params.Bucket, params.ACL, params.Prefix)
			if err != nil {
				Fatal(err)
			}
		} else {
			Fatal(fmt.Errorf("unknown published storage format: %v", name))
		}
		context.publishedStorages[name] = publishedStorage
	}

	return publishedStorage
}
Ejemplo n.º 6
0
func (s *PublishedRepoRemoveSuite) SetUpTest(c *C) {
	s.db, _ = database.OpenDB(c.MkDir())
	s.factory = NewCollectionFactory(s.db)

	s.snapshotCollection = s.factory.SnapshotCollection()

	s.snap1 = NewSnapshotFromPackageList("snap1", []*Snapshot{}, NewPackageList(), "desc1")

	s.snapshotCollection.Add(s.snap1)

	s.repo1, _ = NewPublishedRepo("", "ppa", "anaconda", []string{}, []string{"main"}, []interface{}{s.snap1}, s.factory)
	s.repo2, _ = NewPublishedRepo("", "", "anaconda", []string{}, []string{"main"}, []interface{}{s.snap1}, s.factory)
	s.repo3, _ = NewPublishedRepo("", "ppa", "meduza", []string{}, []string{"main"}, []interface{}{s.snap1}, s.factory)
	s.repo4, _ = NewPublishedRepo("", "ppa", "osminog", []string{}, []string{"contrib"}, []interface{}{s.snap1}, s.factory)
	s.repo5, _ = NewPublishedRepo("files:other", "ppa", "osminog", []string{}, []string{"contrib"}, []interface{}{s.snap1}, s.factory)

	s.collection = s.factory.PublishedRepoCollection()
	s.collection.Add(s.repo1)
	s.collection.Add(s.repo2)
	s.collection.Add(s.repo3)
	s.collection.Add(s.repo4)
	s.collection.Add(s.repo5)

	s.root = c.MkDir()
	s.publishedStorage = files.NewPublishedStorage(s.root)
	s.publishedStorage.MkDir("ppa/dists/anaconda")
	s.publishedStorage.MkDir("ppa/dists/meduza")
	s.publishedStorage.MkDir("ppa/dists/osminog")
	s.publishedStorage.MkDir("ppa/pool/main")
	s.publishedStorage.MkDir("ppa/pool/contrib")
	s.publishedStorage.MkDir("dists/anaconda")
	s.publishedStorage.MkDir("pool/main")

	s.root2 = c.MkDir()
	s.publishedStorage2 = files.NewPublishedStorage(s.root2)
	s.publishedStorage2.MkDir("ppa/dists/osminog")
	s.publishedStorage2.MkDir("ppa/pool/contrib")

	s.provider = &FakeStorageProvider{map[string]aptly.PublishedStorage{
		"":            s.publishedStorage,
		"files:other": s.publishedStorage2}}
}
Ejemplo n.º 7
0
// GetPublishedStorage returns instance of PublishedStorage
func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedStorage {
	context.Lock()
	defer context.Unlock()

	publishedStorage, ok := context.publishedStorages[name]
	if !ok {
		if name == "" {
			publishedStorage = files.NewPublishedStorage(context.config().RootDir)
		} else if strings.HasPrefix(name, "s3:") {
			params, ok := context.config().S3PublishRoots[name[3:]]
			if !ok {
				Fatal(fmt.Errorf("published S3 storage %v not configured", name[3:]))
			}

			var err error
			publishedStorage, err = s3.NewPublishedStorage(
				params.AccessKeyID, params.SecretAccessKey, params.SessionToken,
				params.Region, params.Endpoint, params.Bucket, params.ACL, params.Prefix, params.StorageClass,
				params.EncryptionMethod, params.PlusWorkaround, params.DisableMultiDel,
				params.ForceSigV2, params.Debug)
			if err != nil {
				Fatal(err)
			}
		} else if strings.HasPrefix(name, "swift:") {
			params, ok := context.config().SwiftPublishRoots[name[6:]]
			if !ok {
				Fatal(fmt.Errorf("published Swift storage %v not configured", name[6:]))
			}

			var err error
			publishedStorage, err = swift.NewPublishedStorage(params.UserName, params.Password,
				params.AuthURL, params.Tenant, params.TenantID, params.Domain, params.DomainID, params.TenantDomain, params.TenantDomainID, params.Container, params.Prefix)
			if err != nil {
				Fatal(err)
			}
		} else {
			Fatal(fmt.Errorf("unknown published storage format: %v", name))
		}
		context.publishedStorages[name] = publishedStorage
	}

	return publishedStorage
}
Ejemplo n.º 8
0
// InitContext initializes context with default settings
func InitContext(cmd *commander.Command) error {
	var err error

	context.dependencyOptions = 0
	if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowSuggests
	}
	if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowRecommends
	}
	if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowAllVariants
	}
	if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowSource
	}

	context.architecturesList = utils.Config.Architectures
	optionArchitectures := cmd.Flag.Lookup("architectures").Value.String()
	if optionArchitectures != "" {
		context.architecturesList = strings.Split(optionArchitectures, ",")
	}

	context.progress = console.NewProgress()
	context.progress.Start()

	context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress)

	context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
	if err != nil {
		return fmt.Errorf("can't open database: %s", err)
	}

	context.packagePool = files.NewPackagePool(utils.Config.RootDir)
	context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)

	return nil
}
Ejemplo n.º 9
0
func (s *PackageSuite) TestLinkFromPool(c *C) {
	packagePool := files.NewPackagePool(c.MkDir())
	publishedStorage := files.NewPublishedStorage(c.MkDir())
	p := NewPackageFromControlFile(s.stanza)

	poolPath, _ := packagePool.Path(p.Files()[0].Filename, p.Files()[0].Checksums.MD5)
	err := os.MkdirAll(filepath.Dir(poolPath), 0755)
	c.Assert(err, IsNil)

	file, err := os.Create(poolPath)
	c.Assert(err, IsNil)
	file.Close()

	err = p.LinkFromPool(publishedStorage, packagePool, "", "non-free")
	c.Check(err, IsNil)
	c.Check(p.Files()[0].Filename, Equals, "alien-arena-common_7.40-2_i386.deb")
	c.Check(p.Files()[0].downloadPath, Equals, "pool/non-free/a/alien-arena")

	p.IsSource = true
	err = p.LinkFromPool(publishedStorage, packagePool, "", "non-free")
	c.Check(err, IsNil)
	c.Check(p.Extra()["Directory"], Equals, "pool/non-free/a/alien-arena")
}
Ejemplo n.º 10
0
// InitContext initializes context with default settings
func InitContext(cmd *commander.Command) error {
	var err error

	context.dependencyOptions = 0
	if utils.Config.DepFollowSuggests || cmd.Flag.Lookup("dep-follow-suggests").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowSuggests
	}
	if utils.Config.DepFollowRecommends || cmd.Flag.Lookup("dep-follow-recommends").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowRecommends
	}
	if utils.Config.DepFollowAllVariants || cmd.Flag.Lookup("dep-follow-all-variants").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowAllVariants
	}
	if utils.Config.DepFollowSource || cmd.Flag.Lookup("dep-follow-source").Value.Get().(bool) {
		context.dependencyOptions |= debian.DepFollowSource
	}

	context.architecturesList = utils.Config.Architectures
	optionArchitectures := cmd.Flag.Lookup("architectures").Value.String()
	if optionArchitectures != "" {
		context.architecturesList = strings.Split(optionArchitectures, ",")
	}

	context.progress = console.NewProgress()
	context.progress.Start()

	context.downloader = http.NewDownloader(utils.Config.DownloadConcurrency, context.progress)

	context.database, err = database.OpenDB(filepath.Join(utils.Config.RootDir, "db"))
	if err != nil {
		return fmt.Errorf("can't open database: %s", err)
	}

	context.packagePool = files.NewPackagePool(utils.Config.RootDir)
	context.publishedStorage = files.NewPublishedStorage(utils.Config.RootDir)

	if aptly.EnableDebug {
		cpuprofile := cmd.Flag.Lookup("cpuprofile").Value.String()
		if cpuprofile != "" {
			context.fileCPUProfile, err = os.Create(cpuprofile)
			if err != nil {
				return err
			}
			pprof.StartCPUProfile(context.fileCPUProfile)
		}

		memprofile := cmd.Flag.Lookup("memprofile").Value.String()
		if memprofile != "" {
			context.fileMemProfile, err = os.Create(memprofile)
			if err != nil {
				return err
			}
		}

		memstats := cmd.Flag.Lookup("memstats").Value.String()
		if memstats != "" {
			interval := cmd.Flag.Lookup("meminterval").Value.Get().(time.Duration)

			context.fileMemStats, err = os.Create(memstats)
			if err != nil {
				return err
			}

			context.fileMemStats.WriteString("# Time\tHeapSys\tHeapAlloc\tHeapIdle\tHeapReleased\n")

			go func() {
				var stats runtime.MemStats

				start := time.Now().UnixNano()

				for {
					runtime.ReadMemStats(&stats)
					if context.fileMemStats != nil {
						context.fileMemStats.WriteString(fmt.Sprintf("%d\t%d\t%d\t%d\t%d\n",
							(time.Now().UnixNano()-start)/1000000, stats.HeapSys, stats.HeapAlloc, stats.HeapIdle, stats.HeapReleased))
						time.Sleep(interval)
					} else {
						break
					}
				}
			}()
		}
	}

	return nil
}