Пример #1
0
func (s *archiveSuite) TestNewCanonoicalArchivePaths(c *gc.C) {
	ap := backups.NewCanonicalArchivePaths()

	c.Check(ap.ContentDir, gc.Equals, "juju-backup")
	c.Check(ap.FilesBundle, gc.Equals, "juju-backup/root.tar")
	c.Check(ap.DBDumpDir, gc.Equals, "juju-backup/dump")
	c.Check(ap.MetadataFile, gc.Equals, "juju-backup/metadata.json")
}
Пример #2
0
func extractMachineID(archive *os.File) (string, error) {
	paths := backups.NewCanonicalArchivePaths()

	gzr, err := gzip.NewReader(archive)
	if err != nil {
		return "", errors.Annotate(err, fmt.Sprintf("cannot unzip %q", archive.Name()))
	}
	defer gzr.Close()

	metaFile, err := findFileInTar(gzr, paths.MetadataFile)
	if errors.IsNotFound(err) {
		// Older archives don't have a metadata file and always have machine-0.
		return "0", nil
	}
	if err != nil {
		return "", errors.Trace(err)
	}
	meta, err := backups.NewMetadataJSONReader(metaFile)
	if err != nil {
		return "", errors.Trace(err)
	}
	return meta.Origin.Machine, nil
}