Exemplo n.º 1
0
func downloadArchivedFileWithChecksum(url string, archivedFile string, destPath string) {
	archiveName := path.Base(url)
	tmpPath := filepath.Join(dvmDir, ".tmp", archiveName)
	downloadFileWithChecksum(url, tmpPath)

	// Extract the archive
	archivePath := filepath.Join(dvmDir, ".tmp", strings.TrimSuffix(archiveName, filepath.Ext(archiveName)))
	extractor := extractor.NewDetectable()
	extractor.Extract(tmpPath, archivePath)

	// Copy the archived file to the final destination
	archivedFilePath := filepath.Join(archivePath, archivedFile)
	ensureParentDirectoryExists(destPath)
	err := os.Rename(archivedFilePath, destPath)
	if err != nil {
		die("Unable to copy %s to %s.", err, retCodeRuntimeError, archivedFilePath, destPath)
	}

	// Cleanup temp files
	if err = os.Remove(tmpPath); err != nil {
		writeWarning("Unable to remove temporary file: %s\n%s", tmpPath, err)
	}
	if err = os.RemoveAll(archivePath); err != nil {
		writeWarning("Unable to remove temporary directory: %s\n%s", archivePath, err)
	}
}
Exemplo n.º 2
0
func initializeTransformer(
	logger lager.Logger,
	cachePath, workDir string,
	maxCacheSizeInBytes uint64,
	maxConcurrentDownloads, maxConcurrentUploads uint,
	skipSSLVerification bool,
	exportNetworkEnvVars bool,
	clock clock.Clock,
) *transformer.Transformer {
	cache := cacheddownloader.New(cachePath, workDir, int64(maxCacheSizeInBytes), 10*time.Minute, int(math.MaxInt8), skipSSLVerification)
	uploader := uploader.New(10*time.Minute, skipSSLVerification, logger)
	extractor := extractor.NewDetectable()
	compressor := compressor.NewTgz()

	return transformer.NewTransformer(
		cache,
		uploader,
		extractor,
		compressor,
		make(chan struct{}, maxConcurrentDownloads),
		make(chan struct{}, maxConcurrentUploads),
		workDir,
		exportNetworkEnvVars,
		clock,
	)
}
Exemplo n.º 3
0
func (a *Artifact) Extract() error {
	extractor := extractor.NewDetectable()
	dir := a.Dir("extracted")
	err := os.RemoveAll(dir)
	if err != nil {
		return err
	}
	os.MkdirAll(dir, 0775)
	apath, err := filepath.Abs(a.Path())
	if err != nil {
		return err
	}
	lg.V(5).Infof("extracting %s into %s", apath, dir)
	return extractor.Extract(apath, dir)
}
Exemplo n.º 4
0
	return results
}

var _ = Describe("Tgz Compressor", func() {
	var compressor Compressor
	var destDir string
	var extracticator extractor.Extractor
	var victimFile *os.File
	var victimDir string

	BeforeEach(func() {
		var err error

		compressor = NewTgz()
		extracticator = extractor.NewDetectable()

		destDir, err = ioutil.TempDir("", "")
		Ω(err).ShouldNot(HaveOccurred())

		victimDir, err = ioutil.TempDir("", "")
		Ω(err).ShouldNot(HaveOccurred())

		victimFile, err = ioutil.TempFile("", "")
		Ω(err).ShouldNot(HaveOccurred())

		err = os.Mkdir(filepath.Join(victimDir, "empty"), 0755)
		Ω(err).ShouldNot(HaveOccurred())

		notEmptyDirPath := filepath.Join(victimDir, "not_empty")
Exemplo n.º 5
0
func UnzipWrapper(src, dest string) error {
	e := extractor.NewDetectable()
	return e.Extract(src, dest)
}