MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / writeFiles

Function writeFiles

app/cli/internal/policydevel/init.go:159–176  ·  view source on GitHub ↗
(dir string, files map[string]string, force bool)

Source from the content-addressed store, hash-verified

157}
158
159func writeFiles(dir string, files map[string]string, force bool) error {
160 if err := os.MkdirAll(dir, 0755); err != nil {
161 return fmt.Errorf("failed to create directory: %w", err)
162 }
163
164 for filename, content := range files {
165 path := filepath.Join(dir, filename)
166 if !force && fileExists(path) {
167 return fmt.Errorf("file %s already exists (use --force to overwrite)", path)
168 }
169
170 if err := os.WriteFile(path, []byte(content), 0600); err != nil {
171 return fmt.Errorf("failed to write file %s: %w", filename, err)
172 }
173 }
174
175 return nil
176}
177
178func fileExists(path string) bool {
179 _, err := os.Stat(path)

Callers 1

InitializeFunction · 0.85

Calls 1

fileExistsFunction · 0.85

Tested by

no test coverage detected