github.com/Benchkram/bob@v0.0.0-20220321080157-7c8f3876e225/bobtask/target/exists.go (about)

     1  package target
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/Benchkram/bob/pkg/file"
     7  )
     8  
     9  // Exists determines if the target exists without
    10  // validating it's integrety.
    11  func (t *T) Exists() bool {
    12  	switch t.Type {
    13  	case Path:
    14  		return t.existsFile()
    15  	case Docker:
    16  		return t.existsDocker()
    17  	default:
    18  		return t.existsFile()
    19  	}
    20  }
    21  
    22  func (t *T) existsFile() bool {
    23  	if len(t.Paths) == 0 {
    24  		return true
    25  	}
    26  	// check plain existence
    27  	for _, f := range t.Paths {
    28  		target := filepath.Join(t.dir, f)
    29  		if !file.Exists(target) {
    30  			return false
    31  		}
    32  	}
    33  
    34  	return true
    35  }
    36  
    37  func (t *T) existsDocker() bool {
    38  	if len(t.Paths) == 0 {
    39  		return true
    40  	}
    41  
    42  	for _, f := range t.Paths {
    43  		exists, err := t.dockerRegistryClient.ImageExists(f)
    44  		if err != nil {
    45  			return false
    46  		}
    47  		if !exists {
    48  			return false
    49  		}
    50  	}
    51  
    52  	return true
    53  }