本文整理匯總了Golang中github.com/appc/spec/pkg/acirenderer.ACIProvider類的典型用法代碼示例。如果您正苦於以下問題:Golang ACIProvider類的具體用法?Golang ACIProvider怎麽用?Golang ACIProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ACIProvider類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: writeSquashedImage
func writeSquashedImage(outputFile *os.File, renderedACI acirenderer.RenderedACI, aciProvider acirenderer.ACIProvider, manifests []schema.ImageManifest) error {
gw := gzip.NewWriter(outputFile)
defer gw.Close()
outputWriter := tar.NewWriter(gw)
defer outputWriter.Close()
for _, aciFile := range renderedACI {
rs, err := aciProvider.ReadStream(aciFile.Key)
if err != nil {
return err
}
defer rs.Close()
squashWalker := func(t *tarball.TarFile) error {
cleanName := filepath.Clean(t.Name())
if _, ok := aciFile.FileMap[cleanName]; ok {
// we generate and add the squashed manifest later
if cleanName == "manifest" {
return nil
}
if err := outputWriter.WriteHeader(t.Header); err != nil {
return fmt.Errorf("error writing header: %v", err)
}
if _, err := io.Copy(outputWriter, t.TarStream); err != nil {
return fmt.Errorf("error copying file into the tar out: %v", err)
}
}
return nil
}
tr := tar.NewReader(rs)
if err := tarball.Walk(*tr, squashWalker); err != nil {
return err
}
}
if err := common.WriteRootfsDir(outputWriter); err != nil {
return err
}
finalManifest := mergeManifests(manifests)
if err := common.WriteManifest(outputWriter, finalManifest); err != nil {
return err
}
return nil
}
示例2: renderImage
// Given a RenderedACI, it will extract, under the provided directory, the
// needed files from the right source ACI.
// The manifest will be extracted from the upper ACI.
// No file overwriting is done as it should usually be called
// providing an empty directory.
func renderImage(renderedACI acirenderer.RenderedACI, dir string, ap acirenderer.ACIProvider, uidRange *user.UidRange) error {
for _, ra := range renderedACI {
rs, err := ap.ReadStream(ra.Key)
if err != nil {
return err
}
// Overwrite is not needed. If a file needs to be overwritten then the renderedACI builder has a bug
if err := ptar.ExtractTar(rs, dir, false, uidRange, ra.FileMap); err != nil {
rs.Close()
return errwrap.Wrap(errors.New("error extracting ACI"), err)
}
rs.Close()
}
return nil
}
示例3: writeSquashedImage
func writeSquashedImage(outputFile *os.File, renderedACI acirenderer.RenderedACI, aciProvider acirenderer.ACIProvider, manifests []schema.ImageManifest, compression common.Compression) error {
var tarWriterTarget io.WriteCloser = outputFile
switch compression {
case common.NoCompression:
case common.GzipCompression:
tarWriterTarget = gzip.NewWriter(outputFile)
defer tarWriterTarget.Close()
default:
return fmt.Errorf("unexpected compression enum value: %d", compression)
}
outputWriter := tar.NewWriter(tarWriterTarget)
defer outputWriter.Close()
finalManifest := mergeManifests(manifests)
if err := internal.WriteManifest(outputWriter, finalManifest); err != nil {
return err
}
if err := internal.WriteRootfsDir(outputWriter); err != nil {
return err
}
type hardLinkEntry struct {
firstLinkCleanName string
firstLinkHeader tar.Header
keepOriginal bool
walked bool
}
// map aciFileKey -> cleanTarget -> hardLinkEntry
hardLinks := make(map[string]map[string]hardLinkEntry)
// first pass: read all the entries and build the hardLinks map in memory
// but don't write on disk
for _, aciFile := range renderedACI {
rs, err := aciProvider.ReadStream(aciFile.Key)
if err != nil {
return err
}
defer rs.Close()
hardLinks[aciFile.Key] = map[string]hardLinkEntry{}
squashWalker := func(t *tarball.TarFile) error {
cleanName := filepath.Clean(t.Name())
// the rootfs and the squashed manifest are added separately
if cleanName == "manifest" || cleanName == "rootfs" {
return nil
}
_, keep := aciFile.FileMap[cleanName]
if keep && t.Header.Typeflag == tar.TypeLink {
cleanTarget := filepath.Clean(t.Linkname())
if _, ok := hardLinks[aciFile.Key][cleanTarget]; !ok {
_, keepOriginal := aciFile.FileMap[cleanTarget]
hardLinks[aciFile.Key][cleanTarget] = hardLinkEntry{cleanName, *t.Header, keepOriginal, false}
}
}
return nil
}
tr := tar.NewReader(rs)
if err := tarball.Walk(*tr, squashWalker); err != nil {
return err
}
}
// second pass: write on disk
for _, aciFile := range renderedACI {
rs, err := aciProvider.ReadStream(aciFile.Key)
if err != nil {
return err
}
defer rs.Close()
squashWalker := func(t *tarball.TarFile) error {
cleanName := filepath.Clean(t.Name())
// the rootfs and the squashed manifest are added separately
if cleanName == "manifest" || cleanName == "rootfs" {
return nil
}
_, keep := aciFile.FileMap[cleanName]
if link, ok := hardLinks[aciFile.Key][cleanName]; ok {
if keep != link.keepOriginal {
return fmt.Errorf("logic error: should we keep file %q?", cleanName)
}
if keep {
if err := outputWriter.WriteHeader(t.Header); err != nil {
return fmt.Errorf("error writing header: %v", err)
}
if _, err := io.Copy(outputWriter, t.TarStream); err != nil {
return fmt.Errorf("error copying file into the tar out: %v", err)
}
} else {
// The current file does not remain but there is a hard link pointing to
// it. Write the current file but with the filename of the first hard link
// pointing to it. That first hard link will not be written later, see
// variable "alreadyWritten".
//.........這裏部分代碼省略.........