github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/archive/archiver.go (about) 1 package archive 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 type Archiver interface { 9 ArchiveContent(content []byte, infilename string) error 10 ArchiveFile(infilename string) error 11 ArchiveDir(indirname string) error 12 ArchiveMultiple(content map[string][]byte) error 13 } 14 15 type ArchiverBuilder func(filepath string) Archiver 16 17 var archiverBuilders = map[string]ArchiverBuilder{ 18 "zip": NewZipArchiver, 19 } 20 21 func getArchiver(archiveType string, filepath string) Archiver { 22 if builder, ok := archiverBuilders[archiveType]; ok { 23 return builder(filepath) 24 } 25 return nil 26 } 27 28 func assertValidFile(infilename string) (os.FileInfo, error) { 29 fi, err := os.Stat(infilename) 30 if err != nil && os.IsNotExist(err) { 31 return fi, fmt.Errorf("could not archive missing file: %s", infilename) 32 } 33 return fi, err 34 } 35 36 func assertValidDir(indirname string) (os.FileInfo, error) { 37 fi, err := os.Stat(indirname) 38 if err != nil { 39 if os.IsNotExist(err) { 40 return fi, fmt.Errorf("could not archive missing directory: %s", indirname) 41 } 42 return fi, err 43 } 44 if !fi.IsDir() { 45 return fi, fmt.Errorf("could not archive directory that is a file: %s", indirname) 46 } 47 return fi, nil 48 }