MCPcopy Create free account
hub / github.com/celer-pkg/celer / exportConf

Method exportConf

snapshot/export.go:207–276  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205}
206
207func (e *Exporter) exportConf() error {
208 dstConf := filepath.Join(e.exportDir, "conf")
209
210 // 1. Export only the current platform's .toml file.
211 platformName := e.celer.Platform().GetName()
212 srcPlatformFile := filepath.Join(dirs.ConfPlatformsDir, platformName+".toml")
213 dstPlatformDir := filepath.Join(dstConf, "platforms")
214 if err := os.MkdirAll(dstPlatformDir, os.ModePerm); err != nil {
215 return err
216 }
217 if err := fileio.CopyFile(srcPlatformFile, filepath.Join(dstPlatformDir, platformName+".toml")); err != nil {
218 return fmt.Errorf("failed to copy platform file -> %w", err)
219 }
220
221 // 2. Export only the current project's .toml file and its subdirectory (port overrides).
222 projectName := e.celer.Project().GetName()
223 srcProjectFile := filepath.Join(dirs.ConfProjectsDir, projectName+".toml")
224 dstProjectDir := filepath.Join(dstConf, "projects")
225 if err := os.MkdirAll(dstProjectDir, os.ModePerm); err != nil {
226 return err
227 }
228 if err := fileio.CopyFile(srcProjectFile, filepath.Join(dstProjectDir, projectName+".toml")); err != nil {
229 return fmt.Errorf("failed to copy project file -> %w", err)
230 }
231
232 // Copy project-specific port overrides only for used ports.
233 srcProjectSubdir := filepath.Join(dirs.ConfProjectsDir, projectName)
234 for nameVersion := range e.usedPorts {
235 parts := strings.SplitN(nameVersion, "@", 2)
236 if len(parts) != 2 {
237 continue
238 }
239 srcPortDir := filepath.Join(srcProjectSubdir, parts[0], parts[1])
240 if !fileio.PathExists(srcPortDir) {
241 continue
242 }
243 dstPortDir := filepath.Join(dstProjectDir, projectName, parts[0], parts[1])
244 if err := filepath.Walk(srcPortDir, func(srcPath string, info os.FileInfo, err error) error {
245 if err != nil {
246 return err
247 }
248 relPath, err := filepath.Rel(srcPortDir, srcPath)
249 if err != nil {
250 return err
251 }
252 dstPath := filepath.Join(dstPortDir, relPath)
253 if info.IsDir() {
254 return os.MkdirAll(dstPath, info.Mode())
255 }
256 return fileio.CopyFile(srcPath, dstPath)
257 }); err != nil {
258 return fmt.Errorf("failed to copy project overrides for %s -> %w", nameVersion, err)
259 }
260 }
261
262 // 3. Export only the host's buildtools .toml file.
263 hostName := e.celer.Platform().GetHostName()
264 srcBuildtoolsFile := filepath.Join(dirs.ConfDir, "buildtools", hostName+".toml")

Callers 1

ExportMethod · 0.95

Calls 7

CopyFileFunction · 0.92
PathExistsFunction · 0.92
MkdirAllMethod · 0.80
GetNameMethod · 0.65
PlatformMethod · 0.65
ProjectMethod · 0.65
GetHostNameMethod · 0.65

Tested by

no test coverage detected