MCPcopy Index your code
hub / github.com/devspace-sh/devspace / initClient

Method initClient

pkg/devspace/services/sync/controller.go:323–541  ·  view source on GitHub ↗
(ctx devspacecontext.Context, pod *v1.Pod, arch, container string, syncConfig *latest.SyncConfig, starter sync.DelayedContainerStarter, verbose bool, customLog logpkg.Logger)

Source from the content-addressed store, hash-verified

321}
322
323func (c *controller) initClient(ctx devspacecontext.Context, pod *v1.Pod, arch, container string, syncConfig *latest.SyncConfig, starter sync.DelayedContainerStarter, verbose bool, customLog logpkg.Logger) (*sync.Sync, error) {
324 localPath, containerPath, err := ParseSyncPath(syncConfig.Path)
325 if err != nil {
326 return nil, err
327 }
328
329 // make sure we resolve it correctly
330 localPath = ctx.ResolvePath(localPath)
331
332 upstreamDisabled := syncConfig.DisableUpload
333 downstreamDisabled := syncConfig.DisableDownload
334 compareBy := latest.InitialSyncCompareByMTime
335 if syncConfig.InitialSyncCompareBy != "" {
336 compareBy = syncConfig.InitialSyncCompareBy
337 }
338
339 options := sync.Options{
340 Verbose: verbose,
341 InitialSyncCompareBy: compareBy,
342 InitialSync: syncConfig.InitialSync,
343 UpstreamDisabled: upstreamDisabled,
344 DownstreamDisabled: downstreamDisabled,
345 Log: customLog,
346 Polling: syncConfig.Polling,
347 Starter: starter,
348 ResolveCommand: func(command string, args []string) (string, []string, error) {
349 return hook.ResolveCommand(ctx.Context(), command, args, ctx.WorkingDir(), ctx.Config(), ctx.Dependencies())
350 },
351 }
352
353 if len(syncConfig.ExcludePaths) > 0 {
354 options.ExcludePaths = syncConfig.ExcludePaths
355 }
356
357 // check if local path exists
358 stat, err := os.Stat(localPath)
359 if err != nil {
360 if !os.IsNotExist(err) {
361 return nil, err
362 }
363
364 if !syncConfig.File {
365 err = os.MkdirAll(localPath, os.ModePerm)
366 if err != nil {
367 return nil, err
368 }
369 }
370 } else if !stat.IsDir() {
371 syncConfig.File = true
372 } else if stat.IsDir() && syncConfig.File {
373 return nil, fmt.Errorf("cannot sync %s because its a directory and expected a single file", localPath)
374 }
375
376 // check if its a file that should get synced
377 if syncConfig.File {
378 if path.Base(filepath.ToSlash(localPath)) != path.Base(containerPath) {
379 return nil, fmt.Errorf("if you want to sync a single file, make sure the filename matches on the local and container path. E.g.: local-path/my-file.txt:remote-path/my-file.txt")
380 }

Callers 1

startSyncMethod · 0.95

Calls 15

StopMethod · 0.95
InitUpstreamMethod · 0.95
InitDownstreamMethod · 0.95
ResolveCommandFunction · 0.92
InjectDevSpaceHelperFunction · 0.92
NewSyncFunction · 0.92
ParseSyncPathFunction · 0.85
parseExcludeFileFunction · 0.85
getSyncCommandsFunction · 0.85
StartStreamFunction · 0.85
ResolvePathMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected