| 711 | } |
| 712 | |
| 713 | func removeObsoleteDesignDocs(ctx context.Context, viewStore sgbucket.ViewStore, previewOnly bool, useViews bool) (removedDesignDocs []string, err error) { |
| 714 | |
| 715 | removedDesignDocs = make([]string, 0) |
| 716 | designDocPrefixes := []string{DesignDocSyncGatewayPrefix, DesignDocSyncHousekeepingPrefix} |
| 717 | |
| 718 | versionsToRemove := DesignDocPreviousVersions |
| 719 | |
| 720 | if !useViews { |
| 721 | versionsToRemove = append(versionsToRemove, DesignDocVersion) |
| 722 | } |
| 723 | |
| 724 | for _, previousVersion := range versionsToRemove { |
| 725 | for _, ddocPrefix := range designDocPrefixes { |
| 726 | var ddocName string |
| 727 | if previousVersion == "" { |
| 728 | ddocName = ddocPrefix |
| 729 | } else { |
| 730 | ddocName = fmt.Sprintf(DesignDocFormat, ddocPrefix, previousVersion) |
| 731 | } |
| 732 | |
| 733 | if !previewOnly { |
| 734 | removeDDocErr := viewStore.DeleteDDoc(ddocName) |
| 735 | if removeDDocErr != nil && !IsMissingDDocError(removeDDocErr) { |
| 736 | base.WarnfCtx(ctx, "Unexpected error when removing design doc %q: %s", ddocName, removeDDocErr) |
| 737 | } |
| 738 | // Only include in list of removedDesignDocs if it was actually removed |
| 739 | if removeDDocErr == nil { |
| 740 | removedDesignDocs = append(removedDesignDocs, ddocName) |
| 741 | } |
| 742 | } else { |
| 743 | _, existsDDocErr := viewStore.GetDDoc(ddocName) |
| 744 | if existsDDocErr != nil && !IsMissingDDocError(existsDDocErr) { |
| 745 | base.WarnfCtx(ctx, "Unexpected error when checking existence of design doc %q: %s", ddocName, existsDDocErr) |
| 746 | } |
| 747 | // Only include in list of removedDesignDocs if it exists |
| 748 | if existsDDocErr == nil { |
| 749 | removedDesignDocs = append(removedDesignDocs, ddocName) |
| 750 | } |
| 751 | |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | } |
| 756 | return removedDesignDocs, nil |
| 757 | } |
| 758 | |
| 759 | // Similar to IsDocNotFoundError(), but for the specific error returned by GetDDoc/DeleteDDoc |
| 760 | func IsMissingDDocError(err error) bool { |