Example #1
0
func (av *Writer) write(updates []parser.UpdateData) error {
	av.availableUpdates = updates

	// write temporary header (we need to know the size before storing in tar)
	if err := av.WriteHeader(); err != nil {
		return err
	}

	// archive info
	info := av.getInfo()
	ia := archiver.NewMetadataArchiver(&info, "info")
	if err := ia.Archive(av.aArchiver); err != nil {
		return errors.Wrapf(err, "writer: error archiving info")
	}
	// archive header
	ha := archiver.NewFileArchiver(av.hTmpFile.Name(), "header.tar.gz")
	if err := ha.Archive(av.aArchiver); err != nil {
		return errors.Wrapf(err, "writer: error archiving header")
	}
	// archive data
	if err := av.WriteData(); err != nil {
		return err
	}
	// we've been storing everything in temporary file
	if err := av.aArchiver.Close(); err != nil {
		return errors.New("writer: error closing archive")
	}
	// prevent from closing archiver twice
	av.aArchiver = nil

	if err := av.aTmpFile.Close(); err != nil {
		return errors.New("writer: error closing archive temporary file")
	}
	return os.Rename(av.aTmpFile.Name(), av.aName)
}
Example #2
0
func archiveFiles(tw *tar.Writer, upd []string, dir string) error {
	files := new(metadata.Files)
	for _, u := range upd {
		files.FileList = append(files.FileList, filepath.Base(u))
	}
	a := archiver.NewMetadataArchiver(files, filepath.Join(dir, "files"))
	return a.Archive(tw)
}
Example #3
0
func (av *Writer) WriteHeader() error {
	// store header info
	for _, upd := range av.availableUpdates {
		av.hInfo.Updates =
			append(av.hInfo.Updates, metadata.UpdateType{Type: upd.Type})
	}
	hi := archiver.NewMetadataArchiver(&av.hInfo, "header-info")
	if err := hi.Archive(av.hArchiver); err != nil {
		return errors.Wrapf(err, "writer: can not store header-info")
	}
	for cnt := 0; cnt < len(av.availableUpdates); cnt++ {
		err := av.processNextHeaderDir(&av.availableUpdates[cnt], fmt.Sprintf("%04d", cnt))
		if err == io.EOF {
			break
		} else if err != nil {
			return errors.Wrapf(err, "writer: error processing update directory")
		}
	}
	return av.aHeader.closeHeader()
}