From 73a7754742eba2b3c74417fd3e8d0581db195bd0 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 9 Apr 2018 13:07:59 +0200 Subject: [PATCH] Added option to rebuild the complete calendar --- src/calanonsync/calanonsync.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/calanonsync/calanonsync.go b/src/calanonsync/calanonsync.go index 5ac5bf4..e2db6fa 100644 --- a/src/calanonsync/calanonsync.go +++ b/src/calanonsync/calanonsync.go @@ -8,12 +8,17 @@ import ( "time" ) +var syncSettings = struct { + rebuild bool +}{} + func main() { rootCmd := &cobra.Command{ Use: "calanonsync", Short: "Synchronize a calendar from EWS to CalDAV by event time and an anonymized title only.", Run: runSynchronization, } + rootCmd.Flags().BoolVar(&syncSettings.rebuild, "rebuild", false, "Rebuild all calendar items, no matter if they already exist.") rootCmd.AddCommand(InitSettingsCmd()) @@ -66,6 +71,13 @@ func runSynchronization(cmd *cobra.Command, args []string) { for uid, calDavItem := range calDavItemMap { if ewsItem, ok := relevantEWSItems[uid]; ok { // Good, so we still know the item at least. + + // If we want a full rebuild, we can skip this step + // since we will create new items anyway. + if syncSettings.rebuild { + continue + } + if !ewsItem.Start.Equal(calDavItem.Start()) || !ewsItem.End.Equal(calDavItem.End()) { @@ -92,9 +104,9 @@ func runSynchronization(cmd *cobra.Command, args []string) { } } - // Find items we don't know so far and create them. + // Find items we don't know so far and create them. Also recreate them if we want to rebuild all. for uid, ewsItem := range relevantEWSItems { - if _, ok := calDavItemMap[uid]; !ok { + if _, ok := calDavItemMap[uid]; !ok || syncSettings.rebuild { title := s.Anonymize.Title.Apply(ewsItem.Subject) ical := CreateICal(ewsItem.Hash(), title, ewsItem.Start, ewsItem.End, ewsItem.IsAllDayEvent) calDavItem := CalDAVItem{HRef: uid + ".ics", ICal: ical}