github.com/tri-adam/singularity@v3.1.1+incompatible/internal/pkg/client/cache/oci.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 // OciBlobDir is the directory inside cache.Dir() where oci images are cached 15 OciBlobDir = "oci" 16 // OciTempDir is the directory inside cache.Dir() where splatted out oci images live 17 OciTempDir = "oci-tmp" 18 ) 19 20 // OciBlob returns the directory inside cache.Dir() where oci blobs are cached 21 func OciBlob() string { 22 return updateCacheSubdir(OciBlobDir) 23 } 24 25 // OciTemp returns the directory inside cache.Dir() where splatted out oci images live 26 func OciTemp() string { 27 return updateCacheSubdir(OciTempDir) 28 } 29 30 // OciTempImage creates a OciTempDir/sum directory and returns the abs path of the image 31 func OciTempImage(sum, name string) string { 32 updateCacheSubdir(filepath.Join(OciTempDir, sum)) 33 34 return filepath.Join(OciTemp(), sum, name) 35 } 36 37 // OciTempExists returns whether the image with the given sha sum exists in the OciTemp() cache 38 func OciTempExists(sum, name string) (bool, error) { 39 _, err := os.Stat(OciTempImage(sum, name)) 40 if os.IsNotExist(err) { 41 return false, nil 42 } else if err != nil { 43 return false, err 44 } 45 46 return true, nil 47 }