github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/client/cache/shub.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 // ShubDir is the directory inside the cache.Dir where shub images are cached 15 ShubDir = "shub" 16 ) 17 18 // Shub returns the directory inside the cache.Dir() where shub images are cached 19 func Shub() string { 20 return updateCacheSubdir(ShubDir) 21 } 22 23 // ShubImage creates a directory inside cache.Dir() with the name of the SHA sum of the image 24 func ShubImage(sum, name string) string { 25 updateCacheSubdir(filepath.Join(ShubDir, sum)) 26 27 return filepath.Join(Shub(), sum, name) 28 } 29 30 // ShubImageExists returns whether the image with the SHA sum exists in the ShubImage cache 31 func ShubImageExists(sum, name string) (bool, error) { 32 _, err := os.Stat(ShubImage(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 }