MCPcopy
hub / github.com/zarf-dev/zarf / processComponentFiles

Function processComponentFiles

src/pkg/packager/deploy.go:817–926  ·  view source on GitHub ↗
(ctx context.Context, pkgLayout *layout.PackageLayout, component v1alpha1.ZarfComponent, variableConfig *variables.VariableConfig, values value.Values, stateAccess template.StateAccess)

Source from the content-addressed store, hash-verified

815}
816
817func processComponentFiles(ctx context.Context, pkgLayout *layout.PackageLayout, component v1alpha1.ZarfComponent, variableConfig *variables.VariableConfig, values value.Values, stateAccess template.StateAccess) (err error) {
818 l := logger.From(ctx)
819 start := time.Now()
820 l.Info("copying files", "count", len(component.Files))
821
822 tmpdir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory)
823 if err != nil {
824 return err
825 }
826 defer func() {
827 err = errors.Join(err, os.RemoveAll(tmpdir))
828 }()
829
830 filesDir, err := pkgLayout.GetComponentDir(ctx, tmpdir, component.Name, layout.FilesComponentDir)
831 if err != nil {
832 return err
833 }
834
835 for fileIdx, file := range component.Files {
836 l.Info("loading file", "name", file.Target)
837
838 fileLocation := filepath.Join(filesDir, layout.ComponentFileRelPath(fileIdx, file.Target))
839
840 // If a shasum is specified check it again on deployment as well
841 if file.Shasum != "" {
842 l.Debug("Validating SHASUM", "file", file.Target)
843 if err := helpers.SHAsMatch(fileLocation, file.Shasum); err != nil {
844 return err
845 }
846 }
847
848 // Replace temp target directory and home directory
849 target, err := config.GetAbsHomePath(strings.Replace(file.Target, "###ZARF_TEMP###", pkgLayout.DirPath(), 1))
850 if err != nil {
851 return err
852 }
853 file.Target = target
854
855 fileList := []string{}
856 if helpers.IsDir(fileLocation) {
857 files, err := helpers.RecursiveFileList(fileLocation, nil, false)
858 if err != nil {
859 return err
860 }
861 fileList = append(fileList, files...)
862 } else {
863 fileList = append(fileList, fileLocation)
864 }
865
866 for _, subFile := range fileList {
867 // Check if the file looks like a text file
868 isText, err := helpers.IsTextFile(subFile)
869 if err != nil {
870 return err
871 }
872
873 // If the file is a text file, template it
874 if isText {

Callers 1

deployComponentMethod · 0.85

Calls 15

FromFunction · 0.92
MakeTempDirFunction · 0.92
ComponentFileRelPathFunction · 0.92
GetAbsHomePathFunction · 0.92
NewObjectsFunction · 0.92
ApplyToFileFunction · 0.92
GetComponentDirMethod · 0.80
DirPathMethod · 0.80
ReplaceTextTemplateMethod · 0.80
WithStateMethod · 0.80
WithConstantsMethod · 0.80
WithVariablesMethod · 0.80

Tested by

no test coverage detected