github.com/Cloud-Foundations/Dominator@v0.3.4/dom/lib/buildMissingLists.go (about)

     1  package lib
     2  
     3  import (
     4  	"github.com/Cloud-Foundations/Dominator/lib/filesystem"
     5  	"github.com/Cloud-Foundations/Dominator/lib/hash"
     6  	"github.com/Cloud-Foundations/Dominator/lib/image"
     7  	"github.com/Cloud-Foundations/Dominator/lib/log"
     8  )
     9  
    10  func (sub *Sub) buildMissingLists(img *image.Image, pushComputedFiles bool,
    11  	ignoreMissingComputedFiles bool, logger log.Logger) (
    12  	map[hash.Hash]uint64, map[hash.Hash]struct{}) {
    13  	objectsToFetch := make(map[hash.Hash]uint64)
    14  	objectsToPush := make(map[hash.Hash]struct{})
    15  	for inum, inode := range img.FileSystem.InodeTable {
    16  		if rInode, ok := inode.(*filesystem.RegularInode); ok {
    17  			if rInode.Size > 0 {
    18  				objectsToFetch[rInode.Hash] = rInode.Size
    19  			}
    20  		} else if pushComputedFiles {
    21  			if _, ok := inode.(*filesystem.ComputedRegularInode); ok {
    22  				pathname := img.FileSystem.InodeToFilenamesTable()[inum][0]
    23  				if inode, ok := sub.ComputedInodes[pathname]; !ok {
    24  					if ignoreMissingComputedFiles {
    25  						continue
    26  					}
    27  					logger.Printf(
    28  						"buildMissingLists(%s): missing computed file: %s\n",
    29  						sub, pathname)
    30  					return nil, nil
    31  				} else {
    32  					objectsToPush[inode.Hash] = struct{}{}
    33  				}
    34  			}
    35  		}
    36  	}
    37  	for _, hashVal := range sub.ObjectCache {
    38  		delete(objectsToFetch, hashVal)
    39  		delete(objectsToPush, hashVal)
    40  	}
    41  	for _, inode := range sub.FileSystem.InodeTable {
    42  		if inode, ok := inode.(*filesystem.RegularInode); ok {
    43  			if inode.Size > 0 {
    44  				delete(objectsToFetch, inode.Hash)
    45  				delete(objectsToPush, inode.Hash)
    46  			}
    47  		}
    48  	}
    49  	return objectsToFetch, objectsToPush
    50  }