-
-
Save flavioribeiro/6616faa8ac4a3ebbd5a5f1c4a4f66dee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func (s *DistributionService) purge(files []string, logger *logrus.Logger) { | |
| purge := func(path string) { | |
| err := s.purger.Purge(path) | |
| if err != nil { | |
| logger.WithField("error", err).WithField("path", path).Error("failed to purge path") | |
| } | |
| } | |
| if s.purger != nil && len(files) > 0 { | |
| paths := make([]string, len(files)) | |
| for i, file := range files { | |
| if filepath.Ext(file) != "" { | |
| file, _ = path.Split(file) | |
| } | |
| paths[i] = strings.TrimRight(file, "/") + "/" | |
| } | |
| sort.Strings(paths) | |
| lastPath := paths[0] | |
| purge(lastPath) | |
| for _, p := range paths[1:] { | |
| if !strings.HasPrefix(p, lastPath) { | |
| lastPath = p | |
| purge(p) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment