Skip to content

Instantly share code, notes, and snippets.

@flavioribeiro
Created December 16, 2016 21:40
Show Gist options
  • Select an option

  • Save flavioribeiro/6616faa8ac4a3ebbd5a5f1c4a4f66dee to your computer and use it in GitHub Desktop.

Select an option

Save flavioribeiro/6616faa8ac4a3ebbd5a5f1c4a4f66dee to your computer and use it in GitHub Desktop.
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