// Persist the container history to S3.
502723
func (ch *ContainerHistory) Save() error {
	srcKey := ch.s3Prefix + "/container." + ch.Events[len(ch.Events)-1].Hash + ".json"
	err := ch.s3Client.Copy(ch.s3Bucket, srcKey, ch.s3Bucket, ch.s3Prefix+"/current.json")
	if err != nil {
		return err
	}

	if len(ch.Events) > maxHistoryEntries {
		ch.Events = ch.Events[len(ch.Events)-maxHistoryEntries:]
	}

	buf := bytes.NewBuffer(nil)
	err = json.NewEncoder(buf).Encode(ch.Events)
	if err != nil {
		return err
	}

	return ch.s3Client.Put(ch.s3Bucket, ch.s3Prefix+"/history.json", buf.Bytes(), nil)
}
1131794
func (sp *statePersistence) NewStorage() storage.Storage {
	modelUUID := sp.st.ModelUUID()
	// TODO(ericsnow) Copy the session?
	session := sp.st.session
	store := storage.NewStorage(modelUUID, session)
	return store
}
522094
func s3Customizations(a *API) {
	var strExpires *Shape

	var keepContentMD5Ref = map[string]struct{}{
		"PutObjectInput":  {},
		"UploadPartInput": {},
	}

	for name, s := range a.Shapes {
		// Remove ContentMD5 members unless specified otherwise.
		if _, keep := keepContentMD5Ref[name]; !keep {
			if _, have := s.MemberRefs["ContentMD5"]; have {
				delete(s.MemberRefs, "ContentMD5")
			}
		}

		// Generate getter methods for API operation fields used by customizations.
		for _, refName := range []string{"Bucket", "SSECustomerKey", "CopySourceSSECustomerKey"} {
			if ref, ok := s.MemberRefs[refName]; ok {
				ref.GenerateGetter = true
			}
		}

		// Expires should be a string not time.Time since the format is not
		// enforced by S3, and any value can be set to this field outside of the SDK.
		if strings.HasSuffix(name, "Output") {
			if ref, ok := s.MemberRefs["Expires"]; ok {
				if strExpires == nil {
					newShape := *ref.Shape
					strExpires = &newShape
					strExpires.Type = "string"
					strExpires.refs = []*ShapeRef{}
				}
				ref.Shape.removeRef(ref)
				ref.Shape = strExpires
				ref.Shape.refs = append(ref.Shape.refs, &s.MemberRef)
			}
		}
	}
	s3CustRemoveHeadObjectModeledErrors(a)
}
987169
func (o *FileSystemSaver) Save(store uuid.Store) {

	if store.Timestamp >= o.Timestamp {
		err := o.openAndDo(o.encode, &store)
		if err == nil {
			if o.Report {
				o.Println("file system saver saved", store)
			}
		}
		o.Timestamp = store.Add(o.Duration)
	}
}
987192
func (e *ClientExecutor) CopyContainer(container *docker.Container, excludes []string, copies ...imagebuilder.Copy) error {
	for _, c := range copies {
		// TODO: reuse source
		for _, src := range c.Src {
			glog.V(4).Infof("Archiving %s download=%t fromFS=%t from=%s", src, c.Download, c.FromFS, c.From)
			var r io.Reader
			var closer io.Closer
			var err error
			if len(c.From) > 0 {
				r, closer, err = e.archiveFromContainer(c.From, src, c.Dest)
			} else {
				r, closer, err = e.Archive(c.FromFS, src, c.Dest, c.Download, excludes)
			}
			if err != nil {
				return err
			}

			glog.V(5).Infof("Uploading to %s at %s", container.ID, c.Dest)
			if glog.V(6) {
				logArchiveOutput(r, "Archive file for %s")
			}
			err = e.Client.UploadToContainer(container.ID, docker.UploadToContainerOptions{
				InputStream: r,
				Path:        "/",
			})
			if err := closer.Close(); err != nil {
				glog.Errorf("Error while closing stream container copy stream %s: %v", container.ID, err)
			}
			if err != nil {
				return err
			}
		}
	}
	return nil
}
201859
func (m *MockAgentClient) AddPersistentDisk(arg0 string, arg1 interface{}) error {
	ret := m.ctrl.Call(m, "AddPersistentDisk", arg0, arg1)
	ret0, _ := ret[0].(error)
	return ret0
}
1192161
func (o *ObjectToPack) SaveOriginalMetadata() {
	if o.Original != nil {
		o.originalSize = o.Original.Size()
		o.originalType = o.Original.Type()
		o.originalHash = o.Original.Hash()
		o.resolvedOriginal = true
	}
}
1373347
func (_m *Store) Persist(txid string, blockHeight uint64, privateSimulationResults *rwset.TxPvtReadWriteSet) error {
	ret := _m.Called(txid, blockHeight, privateSimulationResults)

	var r0 error
	if rf, ok := ret.Get(0).(func(string, uint64, *rwset.TxPvtReadWriteSet) error); ok {
		r0 = rf(txid, blockHeight, privateSimulationResults)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
355649
func NewStorageAPIV3(context facade.Context) (*StorageAPIv3, error) {
	storageAPI, err := NewStorageAPIV4(context)
	if err != nil {
		return nil, err
	}
	return &StorageAPIv3{
		StorageAPIv4: *storageAPI,
	}, nil
}
205391
func (v *version) PersistentVolumes() PersistentVolumeInformer {
	return &persistentVolumeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
249131
func (c *Client) Persist(key string) (bool, error) {
	var ret bool

	err := c.command(
		&ret,
		[]byte("PERSIST"),
		[]byte(key),
	)

	return ret, err
}
112160
func (s *Snapshot) Persist(sink raft.SnapshotSink) (err error) {
	defer func() {
		if err != nil {
			sink.Cancel()
		}
	}()

	encoder := yaml.NewEncoder(sink)
	if err := encoder.Encode(s); err != nil {
		return errors.Trace(err)
	}
	if err := encoder.Close(); err != nil {
		return errors.Trace(err)
	}
	return sink.Close()
}
1088407
func (snap *SimpleSnapshot) Persist(sink raft.SnapshotSink) error {
	if err := gob.NewEncoder(sink).Encode(snap.logs[:snap.n]); err != nil {
		sink.Cancel()
		return err
	}
	sink.Close()
	return nil
}
968571
func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
	container, err := daemon.GetContainer(name)
	if err != nil {
		return nil, err
	}

	// Make sure an online file-system operation is permitted.
	if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
		return nil, errdefs.System(err)
	}

	data, err := daemon.containerCopy(container, res)
	if err == nil {
		return data, nil
	}

	if os.IsNotExist(err) {
		return nil, containerFileNotFound{res, name}
	}
	return nil, errdefs.System(err)
}
388958
func (dr *dockerMetadataStorage) Save(resourceID string, drInfo resources.DockerImageDetails) error {
	doc := dockerMetadataDoc{
		Id:           resourceID,
		RegistryPath: drInfo.RegistryPath,
		Username:     drInfo.Username,
		Password:     drInfo.Password,
	}

	buildTxn := func(int) ([]txn.Op, error) {
		existing, err := dr.get(resourceID)
		if err != nil && !errors.IsNotFound(err) {
			return nil, errors.Annotate(err, "failed to check for existing resource")

		}
		if !errors.IsNotFound(err) {
			return []txn.Op{{
				C:      dockerResourcesC,
				Id:     existing.Id,
				Assert: txn.DocExists,
				Update: bson.D{
					{"$set",
						bson.D{
							{"registry-path", doc.RegistryPath},
							{"username", doc.Username},
							{"password", doc.Password},
						},
					},
				},
			}}, nil
		}

		return []txn.Op{{
			C:      dockerResourcesC,
			Id:     doc.Id,
			Assert: txn.DocMissing,
			Insert: doc,
		}}, nil
	}

	err := dr.st.db().Run(buildTxn)
	return errors.Annotate(err, "failed to store Docker resource")
}
1014546
func (h *history) append(b []byte) {
	if len(b) >= h.windowSize {
		// Discard all history by simply overwriting
		h.b = h.b[:h.windowSize]
		copy(h.b, b[len(b)-h.windowSize:])
		return
	}

	// If there is space, append it.
	if len(b) < cap(h.b)-len(h.b) {
		h.b = append(h.b, b...)
		return
	}

	// Move data down so we only have window size left.
	// We know we have less than window size in b at this point.
	discard := len(b) + len(h.b) - h.windowSize
	copy(h.b, h.b[discard:])
	h.b = h.b[:h.windowSize]
	copy(h.b[h.windowSize-len(b):], b)
}
808034
func (sp *StandardProvider) Persistent() bool {
	return sp.Paths.KeyFile != "" && sp.Paths.CertFile != ""
}