示例#1
0
文件: util.go 项目: getcarina/dvm
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)
	}
}
示例#2
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)
}