2014-04-10 4 views
3

특정 폴더 안에있는 텍스트 파일 집합에 데이터를 저장하는 응용 프로그램을 작성하고 있습니다. 그리고 Dropbox 나 TextEdit 같은 다른 앱이 파일을 변경하면 알림을받을 FSEventStream이 있으므로 제공되는 새 텍스트 콘텐츠로 애플리케이션을 업데이트 할 수 있습니다.FSEventStream - 내 응용 프로그램에서 생성 된 이벤트 필터링

문제는입니다 내 FSEventStream - 나는 kFSEventStreamCreateFlagIgnoreSelf 플래그를 설정에도 불구하고 - 내 자신의 응용 프로그램 내에서 파일을 수정하는 경우에도 나는 알림을받을 수 있습니다.

파일을 저장하고 파일 변경 알림을 받으면 파일을 다시 확인해야하기 때문에 많은 문제가 발생합니다. 여기서 최적화에 대해 이야기 할 수는 있지만 데이터 구조가 불필요한 작업과 디스크 사용량이 많습니다.

질문 : a) 다른 응용 프로그램에서 파일 이벤트를 b)에서 분리 할 수있는 방법 b) 내 응용 프로그램에서 생성 된 파일 이벤트?

나는 processID를 FSEventID로 가져 오는 방법이있을 것이라고 생각했다. 후자는 콜백 함수에서 제공된다. 그러나 그것에 관해 아무것도 발견하지 못했습니다. 그리고 EventID가 FileEvents의 체인에서 순서를 정의하기 위해서만 제공되는 것처럼 보입니다.

내가 원하는 것은 자체 생성 FileSystem 이벤트를 무시하는 것입니다.

NSArray * pathArray = [NSArray arrayWithObject:_pathToObserve]; 

FSEventStreamContext context; 
context.info = self; 
context.version = 0; 
context.retain = NULL; 
context.release = NULL; 
context.copyDescription = NULL; 

_fsEventStream = FSEventStreamCreate(NULL, 
            filesystemObserverCallback, 
            &context, 
            (CFArrayRef)pathArray, 
            kFSEventStreamEventIdSinceNow, 
            1.0, 
            kFSEventStreamCreateFlagIgnoreSelf|kFSEventStreamCreateFlagFileEvents|kFSEventStreamCreateFlagUseCFTypes); 

FSEventStreamScheduleWithRunLoop(_fsEventStream, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 
FSEventStreamStart(_fsEventStream); 

그리고 콜백 함수 :

void filesystemObserverCallback(ConstFSEventStreamRef streamRef, 
           void * clientCallBackInfo, 
           size_t numEvents, 
           void * eventPaths, 
           const FSEventStreamEventFlags eventFlags[], 
           const FSEventStreamEventId eventIds[]) 
{ 

    NSArray * pathArray = (NSArray *)eventPaths; 

    for (int i=0; i < numEvents; i++) 
    { 
     NSString * path = [pathArray objectAtIndex:i]; 
     FSEventStreamEventFlags flags = flagsArray[i]; 

     if (flags & kFSEventStreamEventFlagItemCreated || 
      flags & kFSEventStreamEventFlagItemRemoved || 
      flags & kFSEventStreamEventFlagItemRenamed || 
      flags & kFSEventStreamEventFlagItemFinderInfoMod || 
      flags & kFSEventStreamEventFlagItemChangeOwner || 
      flags & kFSEventStreamEventFlagItemXattrMod) 
     { 

      NSLog(@">> item has changed at path: %@", path); 
     } 
    } 
} 
+1

파일의 변경 내용을 수신 할 경우를 대비해 표시되지 않는 것처럼 보입니다. 아마도 "자기 무시"는 폴더 수준에서만 작동합니다 ... – UJey

답변

0

kFSEventStreamCreateFlagIgnoreSelf 이외에 FSEventStreamCreate에 플래그로 kFSEventStreamCreateFlagMarkSelf을 설정해보십시오 여기

내가 FSEventStream 설치에 사용하는 코드입니다. 이것은 나를 위해 일했다.

나는 "own"플래그가 전혀 생성되지 않도록하기 때문에 무시할 수 있습니다. 그것이 또한 당신을 위해 일하는 경우 알려 주시기 바랍니다.

0

osxdirk의 답변은 분명히 효과가 있어야합니다. FSEvents.h 출신 :

/* 
    * Indicates the event was triggered by the current process. 
    * (This flag is only ever set if you specified the MarkSelf flag when creating the stream.) 
    */ 
    kFSEventStreamEventFlagOwnEvent __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) = 0x00080000,