From 68043cfcacd4c35e86d063a08bf0de2cfbf5f7ad Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 14 Nov 2020 21:21:58 -0800 Subject: [PATCH] add reference implementation to detect create/update/delete/rename events --- weed/pb/filer_pb/filer_pb_helper.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/weed/pb/filer_pb/filer_pb_helper.go b/weed/pb/filer_pb/filer_pb_helper.go index bc0fac36c..75e37ca1b 100644 --- a/weed/pb/filer_pb/filer_pb_helper.go +++ b/weed/pb/filer_pb/filer_pb_helper.go @@ -121,3 +121,20 @@ func LookupEntry(client SeaweedFilerClient, request *LookupDirectoryEntryRequest } var ErrNotFound = errors.New("filer: no entry is found in filer store") + +func IsCreate(event *SubscribeMetadataResponse) bool { + return event.EventNotification.NewEntry != nil && event.EventNotification.OldEntry == nil +} +func IsUpdate(event *SubscribeMetadataResponse) bool { + return event.EventNotification.NewEntry != nil && + event.EventNotification.OldEntry != nil && + event.Directory == event.EventNotification.NewParentPath +} +func IsDelete(event *SubscribeMetadataResponse) bool { + return event.EventNotification.NewEntry == nil && event.EventNotification.OldEntry != nil +} +func IsRename(event *SubscribeMetadataResponse) bool { + return event.EventNotification.NewEntry != nil && + event.EventNotification.OldEntry != nil && + event.Directory != event.EventNotification.NewParentPath +}