func (gdw *NaiveDiffDriver) DiffSize(id string, idMappings *idtools.IDMappings, parent string, parentMappings *idtools.IDMappings, mountLabel string) (size int64, err error) {
	driver := gdw.ProtoDriver
	if idMappings == nil {
		idMappings = &idtools.IDMappings{}
	}
	if parentMappings == nil {
		parentMappings = &idtools.IDMappings{}
	}
	changes, err := gdw.Changes(id, idMappings, parent, parentMappings, mountLabel)
	if err != nil {
		return
	}
	options := MountOpts{
		MountLabel: mountLabel,
	}
	layerFs, err := driver.Get(id, options)
	if err != nil {
		return
	}
	defer driver.Put(id)
	return archive.ChangesSize(layerFs, changes), nil
}
DiffSize calculates the changes between the specified layer
and its parent and returns the size in bytes of the changes
relative to its base filesystem directory.
package graphdriver
import (
	"io"
	"time"
	"github.com/containers/storage/pkg/archive"
	"github.com/containers/storage/pkg/chrootarchive"
	"github.com/containers/storage/pkg/idtools"
	"github.com/containers/storage/pkg/ioutils"
	"github.com/opencontainers/runc/libcontainer/userns"
	"github.com/sirupsen/logrus"
)
var (
	ApplyUncompressedLayer = chrootarchive.ApplyUncompressedLayer
)
type NaiveDiffDriver struct {
	ProtoDriver
	LayerIDMapUpdater
}
func NewNaiveDiffDriver(driver ProtoDriver, updater LayerIDMapUpdater) Driver {
	return &NaiveDiffDriver{ProtoDriver: driver, LayerIDMapUpdater: updater}
}
func (gdw *NaiveDiffDriver) Diff(id string, idMappings *idtools.IDMappings, parent string, parentMappings *idtools.IDMappings, mountLabel string) (arch io.ReadCloser, err error) {
	startTime := time.Now()
	driver := gdw.ProtoDriver
	if idMappings == nil {
		idMappings = &idtools.IDMappings{}
	}
	if parentMappings == nil {
		parentMappings = &idtools.IDMappings{}
	}
	options := MountOpts{
		MountLabel: mountLabel,
	}
	layerFs, err := driver.Get(id, options)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			driver.Put(id)
		}
	}()
	if parent == "" {
		archive, err := archive.TarWithOptions(layerFs, &archive.TarOptions{
			Compression: archive.Uncompressed,
			UIDMaps:     idMappings.UIDs(),
			GIDMaps:     idMappings.GIDs(),
		})
		if err != nil {
			return nil, err
		}
		return ioutils.NewReadCloserWrapper(archive, func() error {
			err := archive.Close()
			driver.Put(id)
			return err
		}), nil
	}
	options.Options = append(options.Options, "ro")
	parentFs, err := driver.Get(parent, options)
	if err != nil {
		return nil, err
	}
	defer driver.Put(parent)
	changes, err := archive.ChangesDirs(layerFs, idMappings, parentFs, parentMappings)
	if err != nil {
		return nil, err
	}
	archive, err := archive.ExportChanges(layerFs, changes, idMappings.UIDs(), idMappings.GIDs())
	if err != nil {
		return nil, err
	}
	return ioutils.NewReadCloserWrapper(archive, func() error {
		err := archive.Close()
		driver.Put(id)
		time.Sleep(startTime.Truncate(time.Second).Add(time.Second).Sub(time.Now()))
		return err
	}), nil
}
func (gdw *NaiveDiffDriver) Changes(id string, idMappings *idtools.IDMappings, parent string, parentMappings *idtools.IDMappings, mountLabel string) ([]archive.Change, error) {
	driver := gdw.ProtoDriver
	if idMappings == nil {
		idMappings = &idtools.IDMappings{}
	}
	if parentMappings == nil {
		parentMappings = &idtools.IDMappings{}
	}
	options := MountOpts{
		MountLabel: mountLabel,
	}
	layerFs, err := driver.Get(id, options)
	if err != nil {
		return nil, err
	}
	defer driver.Put(id)
	parentFs := ""
	if parent != "" {
		options := MountOpts{
			MountLabel: mountLabel,
		}
		parentFs, err = driver.Get(parent, options)
		if err != nil {
			return nil, err
		}
		defer driver.Put(parent)
	}
	return archive.ChangesDirs(layerFs, idMappings, parentFs, parentMappings)
}
func (gdw *NaiveDiffDriver) ApplyDiff(id, parent string, options ApplyDiffOpts) (size int64, err error) {
	driver := gdw.ProtoDriver
	if options.Mappings == nil {
		options.Mappings = &idtools.IDMappings{}
	}
	mountOpts := MountOpts{
		MountLabel: options.MountLabel,
	}
	layerFs, err := driver.Get(id, mountOpts)
	if err != nil {
		return
	}
	defer driver.Put(id)
	tarOptions := &archive.TarOptions{
		InUserNS:          userns.RunningInUserNS(),
		IgnoreChownErrors: options.IgnoreChownErrors,
	}
	if options.Mappings != nil {
		tarOptions.UIDMaps = options.Mappings.UIDs()
		tarOptions.GIDMaps = options.Mappings.GIDs()
	}
	start := time.Now().UTC()
	logrus.Debug("Start untar layer")
	if size, err = ApplyUncompressedLayer(layerFs, options.Diff, tarOptions); err != nil {
		logrus.Errorf("While applying layer: %s", err)
		return
	}
	logrus.Debugf("Untar time: %vs", time.Now().UTC().Sub(start).Seconds())
	return
}