MCPcopy
hub / github.com/docker/compose / initialSyncFiles

Method initialSyncFiles

pkg/compose/watch.go:774–835  ·  pkg/compose/watch.go::composeService.initialSyncFiles

Syncs files from develop.watch.path if they have been modified after the image has been created nolint:gocyclo

(ctx context.Context, project *types.Project, service types.ServiceConfig, trigger types.Trigger, ignore watch.PathMatcher)

Source from the content-addressed store, hash-verified

772//
773//nolint:gocyclo
774func (s *composeService) initialSyncFiles(ctx context.Context, project *types.Project, service types.ServiceConfig, trigger types.Trigger, ignore watch.PathMatcher) ([]*sync.PathMapping, error) {
775 fi, err := os.Stat(trigger.Path)
776 if err != nil {
777 return nil, err
778 }
779 timeImageCreated, err := s.imageCreatedTime(ctx, project, service.Name)
780 if err != nil {
781 return nil, err
782 }
783 var pathsToCopy []*sync.PathMapping
784 switch mode := fi.Mode(); {
785 case mode.IsDir():
786 // process directory
787 err = filepath.WalkDir(trigger.Path, func(path string, d fs.DirEntry, err error) error {
788 if err != nil {
789 // handle possible path err, just in case...
790 return err
791 }
792 if trigger.Path == path {
793 // walk starts at the root directory
794 return nil
795 }
796 if shouldIgnore(filepath.Base(path), ignore) || checkIfPathAlreadyBindMounted(path, service.Volumes) {
797 // By definition sync ignores bind mounted paths
798 if d.IsDir() {
799 // skip folder
800 return fs.SkipDir
801 }
802 return nil // skip file
803 }
804 info, err := d.Info()
805 if err != nil {
806 return err
807 }
808 if !d.IsDir() {
809 if info.ModTime().Before(timeImageCreated) {
810 // skip file if it was modified before image creation
811 return nil
812 }
813 rel, err := filepath.Rel(trigger.Path, path)
814 if err != nil {
815 return err
816 }
817 // only copy files (and not full directories)
818 pathsToCopy = append(pathsToCopy, &sync.PathMapping{
819 HostPath: path,
820 ContainerPath: filepath.Join(trigger.Target, rel),
821 })
822 }
823 return nil
824 })
825 case mode.IsRegular():
826 // process file
827 if fi.ModTime().After(timeImageCreated) && !shouldIgnore(filepath.Base(trigger.Path), ignore) && !checkIfPathAlreadyBindMounted(trigger.Path, service.Volumes) {
828 pathsToCopy = append(pathsToCopy, &sync.PathMapping{
829 HostPath: trigger.Path,
830 ContainerPath: trigger.Target,
831 })

Callers 1

initialSyncMethod · 0.95

Calls 4

imageCreatedTimeMethod · 0.95
shouldIgnoreFunction · 0.85
InfoMethod · 0.45

Tested by

no test coverage detected