// DeepCopy makes a complete copy of a DirBlock
480083
func (db *DirBlock) DeepCopy() *DirBlock {
	childrenCopy := make(map[string]DirEntry, len(db.Children))
	for k, v := range db.Children {
		childrenCopy[k] = v
	}
	var iptrsCopy []IndirectDirPtr
	if db.IsInd {
		iptrsCopy = make([]IndirectDirPtr, len(db.IPtrs))
		copy(iptrsCopy, db.IPtrs)
	}
	return &DirBlock{
		CommonBlock: db.CommonBlock.DeepCopy(),
		Children:    childrenCopy,
		IPtrs:       iptrsCopy,
	}
}
435390
func (fd *FileData) DeepCopy(ctx context.Context, dataVer Ver) (
	newTopPtr BlockPointer, allChildPtrs []BlockPointer, err error) {
	topBlock, _, err := fd.getter(ctx, fd.tree.kmd, fd.rootBlockPointer(),
		fd.tree.file, BlockRead)
	if err != nil {
		return ZeroPtr, nil, err
	}

	// Handle the single-level case first.
	if !topBlock.IsInd {
		newTopBlock := topBlock.DeepCopy()
		if err != nil {
			return ZeroPtr, nil, err
		}

		newTopPtr = fd.rootBlockPointer()
		newTopPtr.RefNonce, err = kbfsblock.MakeRefNonce()
		if err != nil {
			return ZeroPtr, nil, err
		}
		newTopPtr.SetWriter(fd.tree.chargedTo)

		if err = fd.tree.cacher(ctx, newTopPtr, newTopBlock); err != nil {
			return ZeroPtr, nil, err
		}

		fd.tree.vlog.CLogf(
			ctx, libkb.VLog1, "Deep copied file %s: %v -> %v",
			fd.tree.file.TailName(), fd.rootBlockPointer(), newTopPtr)

		return newTopPtr, nil, nil
	}

	// For indirect files, get all the paths to leaf blocks.
	pfr, err := fd.tree.getIndirectBlocksForOffsetRange(
		ctx, topBlock, Int64Offset(0), nil)
	if err != nil {
		return ZeroPtr, nil, err
	}
	if len(pfr) == 0 {
		return ZeroPtr, nil,
			fmt.Errorf("Indirect file %v had no indirect blocks",
				fd.rootBlockPointer())
	}

	// Make a new reference for all leaf blocks first.
	copiedBlocks := make(map[BlockPointer]*FileBlock)
	leafLevel := len(pfr[0]) - 1
	for level := leafLevel; level >= 0; level-- {
		for _, Path := range pfr {
			// What is the current ptr for this pblock?
			ptr := fd.rootBlockPointer()
			if level > 0 {
				ptr = Path[level-1].childBlockPtr()
			}
			if _, ok := copiedBlocks[ptr]; ok {
				continue
			}

			// Copy the parent block and save it for later (it will be
			// cached below).
			pblock := Path[level].pblock.(*FileBlock).DeepCopy()
			if err != nil {
				return ZeroPtr, nil, err
			}
			copiedBlocks[ptr] = pblock

			for i, iptr := range pblock.IPtrs {
				if level == leafLevel {
					// Generate a new nonce for each indirect pointer
					// to a leaf.
					iptr.RefNonce, err = kbfsblock.MakeRefNonce()
					if err != nil {
						return ZeroPtr, nil, err
					}
					iptr.SetWriter(fd.tree.chargedTo)
					pblock.IPtrs[i] = iptr
					allChildPtrs = append(allChildPtrs, iptr.BlockPointer)
				} else {
					// Generate a new random ID for each indirect
					// pointer to an indirect block.
					newID, err := kbfsblock.MakeTemporaryID()
					if err != nil {
						return ZeroPtr, nil, err
					}
					// No need for a new refnonce here, since indirect
					// blocks are guaranteed to get a new block ID
					// when readied, since the child block pointers
					// will have changed.
					newPtr := BlockPointer{
						ID:      newID,
						KeyGen:  fd.tree.kmd.LatestKeyGeneration(),
						DataVer: dataVer,
						Context: kbfsblock.MakeFirstContext(
							fd.tree.chargedTo,
							fd.rootBlockPointer().GetBlockType()),
						DirectType: IndirectBlock,
					}
					pblock.IPtrs[i].BlockPointer = newPtr
					allChildPtrs = append(allChildPtrs, newPtr)
					childBlock, ok := copiedBlocks[iptr.BlockPointer]
					if !ok {
						return ZeroPtr, nil, fmt.Errorf(
							"No copied child block found for ptr %v",
							iptr.BlockPointer)
					}
					err = fd.tree.cacher(ctx, newPtr, childBlock)
					if err != nil {
						return ZeroPtr, nil, err
					}
				}
			}
		}
	}

	// Finally, make a new ID for the top block and cache it.
	newTopPtr = fd.rootBlockPointer()
	newID, err := kbfsblock.MakeTemporaryID()
	if err != nil {
		return ZeroPtr, nil, err
	}
	newTopPtr = BlockPointer{
		ID:      newID,
		KeyGen:  fd.tree.kmd.LatestKeyGeneration(),
		DataVer: dataVer,
		Context: kbfsblock.MakeFirstContext(
			fd.tree.chargedTo, fd.rootBlockPointer().GetBlockType()),
		DirectType: IndirectBlock,
	}
	fd.tree.vlog.CLogf(
		ctx, libkb.VLog1, "Deep copied indirect file %s: %v -> %v",
		fd.tree.file.TailName(), fd.rootBlockPointer(), newTopPtr)

	newTopBlock, ok := copiedBlocks[fd.rootBlockPointer()]
	if !ok {
		return ZeroPtr, nil, fmt.Errorf(
			"No copied root block found for ptr %v",
			fd.rootBlockPointer())
	}
	if err = fd.tree.cacher(ctx, newTopPtr, newTopBlock); err != nil {
		return ZeroPtr, nil, err
	}

	return newTopPtr, allChildPtrs, nil
}
225727
func (in *RBDVolumeSource) DeepCopy() *RBDVolumeSource {
	if in == nil {
		return nil
	}
	out := new(RBDVolumeSource)
	in.DeepCopyInto(out)
	return out
}
946269
func (in *ContainerStateTerminated) DeepCopy() *ContainerStateTerminated {
	if in == nil {
		return nil
	}
	out := new(ContainerStateTerminated)
	in.DeepCopyInto(out)
	return out
}
1010343
func (in *DaemonSetUpdateStrategy) DeepCopy() *DaemonSetUpdateStrategy {
	if in == nil {
		return nil
	}
	out := new(DaemonSetUpdateStrategy)
	in.DeepCopyInto(out)
	return out
}
798237
func (in *Headers) DeepCopy() *Headers {
	if in == nil {
		return nil
	}
	out := new(Headers)
	in.DeepCopyInto(out)
	return out
}
878265
func (in *CustomResourceDefinitionStatus) DeepCopy() *CustomResourceDefinitionStatus {
	if in == nil {
		return nil
	}
	out := new(CustomResourceDefinitionStatus)
	in.DeepCopyInto(out)
	return out
}
451511
func (in *OpenstackBlockStorageConfig) DeepCopy() *OpenstackBlockStorageConfig {
	if in == nil {
		return nil
	}
	out := new(OpenstackBlockStorageConfig)
	in.DeepCopyInto(out)
	return out
}
209180
func (in *VolumeProjection) DeepCopy() *VolumeProjection {
	if in == nil {
		return nil
	}
	out := new(VolumeProjection)
	in.DeepCopyInto(out)
	return out
}
1035802
func (in *CustomBuildStrategy) DeepCopy() *CustomBuildStrategy {
	if in == nil {
		return nil
	}
	out := new(CustomBuildStrategy)
	in.DeepCopyInto(out)
	return out
}
254401
func (in *ClusterRoleBindingAdapter) DeepCopy() *ClusterRoleBindingAdapter {
	if in == nil {
		return nil
	}
	out := new(ClusterRoleBindingAdapter)
	in.DeepCopyInto(out)
	return out
}
951942
func (in *ApplicationSourceDirectory) DeepCopy() *ApplicationSourceDirectory {
	if in == nil {
		return nil
	}
	out := new(ApplicationSourceDirectory)
	in.DeepCopyInto(out)
	return out
}
299405
func (in *HostPathVolumeSource) DeepCopy() *HostPathVolumeSource {
	if in == nil {
		return nil
	}
	out := new(HostPathVolumeSource)
	in.DeepCopyInto(out)
	return out
}
1280713
func (in *VolumeSnapshotDataListCopy) DeepCopy() *VolumeSnapshotDataListCopy {
	if in == nil {
		return nil
	}
	out := new(VolumeSnapshotDataListCopy)
	in.DeepCopyInto(out)
	return out
}
384974
func (in *BuildStatus) DeepCopy() *BuildStatus {
	if in == nil {
		return nil
	}
	out := new(BuildStatus)
	in.DeepCopyInto(out)
	return out
}
805870
func (in *ConfigManagementPlugin) DeepCopy() *ConfigManagementPlugin {
	if in == nil {
		return nil
	}
	out := new(ConfigManagementPlugin)
	in.DeepCopyInto(out)
	return out
}
619902
func (in *PersistentVolumeSource) DeepCopy() *PersistentVolumeSource {
	if in == nil {
		return nil
	}
	out := new(PersistentVolumeSource)
	in.DeepCopyInto(out)
	return out
}