| 146 | } |
| 147 | |
| 148 | func (r watchRule) Matches(event watch.FileEvent) *sync.PathMapping { |
| 149 | hostPath := string(event) |
| 150 | if !pathutil.IsChild(r.Path, hostPath) { |
| 151 | return nil |
| 152 | } |
| 153 | included, err := r.include.Matches(hostPath) |
| 154 | if err != nil { |
| 155 | logrus.Warnf("error include matching %q: %v", hostPath, err) |
| 156 | return nil |
| 157 | } |
| 158 | if !included { |
| 159 | logrus.Debugf("%s is not matching include pattern", hostPath) |
| 160 | return nil |
| 161 | } |
| 162 | isIgnored, err := r.ignore.Matches(hostPath) |
| 163 | if err != nil { |
| 164 | logrus.Warnf("error ignore matching %q: %v", hostPath, err) |
| 165 | return nil |
| 166 | } |
| 167 | |
| 168 | if isIgnored { |
| 169 | logrus.Debugf("%s is matching ignore pattern", hostPath) |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | var containerPath string |
| 174 | if r.Target != "" { |
| 175 | rel, err := filepath.Rel(r.Path, hostPath) |
| 176 | if err != nil { |
| 177 | logrus.Warnf("error making %s relative to %s: %v", hostPath, r.Path, err) |
| 178 | return nil |
| 179 | } |
| 180 | // always use Unix-style paths for inside the container |
| 181 | containerPath = path.Join(r.Target, filepath.ToSlash(rel)) |
| 182 | } |
| 183 | return &sync.PathMapping{ |
| 184 | HostPath: hostPath, |
| 185 | ContainerPath: containerPath, |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | func (s *composeService) watch(ctx context.Context, project *types.Project, options api.WatchOptions) (func() error, error) { //nolint: gocyclo |
| 190 | var err error |