github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/client/cache/net.go (about)

     1  // Copyright (c) 2018, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package cache
     7  
     8  import (
     9  	"os"
    10  	"path/filepath"
    11  )
    12  
    13  const (
    14  	// NetDir is the directory inside the cache.Dir where net images are cached
    15  	NetDir = "net"
    16  )
    17  
    18  // Net returns the directory inside the cache.Dir() where shub images are cached
    19  func Net() string {
    20  	return updateCacheSubdir(NetDir)
    21  }
    22  
    23  // NetImage creates a directory inside cache.Dir() with the name of the SHA sum of the image
    24  func NetImage(sum, name string) string {
    25  	updateCacheSubdir(filepath.Join(NetDir, sum))
    26  
    27  	return filepath.Join(Net(), sum, name)
    28  }
    29  
    30  // NetImageExists returns whether the image with the SHA sum exists in the net cache
    31  func NetImageExists(sum, name string) (bool, error) {
    32  	_, err := os.Stat(NetImage(sum, name))
    33  	if os.IsNotExist(err) {
    34  		return false, nil
    35  	} else if err != nil {
    36  		return false, err
    37  	}
    38  
    39  	return true, nil
    40  }