diff --git a/bin/mac/fsnotifier b/bin/mac/fsnotifier index 3d3428f4c764..39b169a7878f 100755 Binary files a/bin/mac/fsnotifier and b/bin/mac/fsnotifier differ diff --git a/native/fsNotifier/mac/fsnotifier.c b/native/fsNotifier/mac/fsnotifier.c index fb7d3ba16be3..5a6948775505 100644 --- a/native/fsNotifier/mac/fsnotifier.c +++ b/native/fsNotifier/mac/fsnotifier.c @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,141 +15,44 @@ */ #include +#include #include -static int ReportMountedFileSystems() - // If fsBuf is too small to account for all volumes, getfsstat will - // silently truncate the returned information. Worse yet, it returns - // the number of volumes it passed back, not the number of volumes present, - // so you can't tell if the list was truncated. - // - // So, in order to get an accurate snapshot of the volume list, I call - // getfsstat with a NULL fsBuf to get a count (fsCountOrig), then allocate a - // buffer that holds (fsCountOrig + 1) items, then call getfsstat again with - // that buffer. If the list was silently truncated, the second count (fsCount) - // will be (fsCountOrig + 1), and we loop to try again. -{ - int err; - int fsCountOrig; - int fsCount; - struct statfs * fsBuf; - bool done; - - - fsBuf = NULL; - fsCount = 0; - - done = false; - do { - // Get the initial count. - err = 0; - fsCountOrig = getfsstat(NULL, 0, MNT_WAIT); - if (fsCountOrig < 0) { - err = errno; - } - - // Allocate a buffer for fsCountOrig + 1 items. - if (err == 0) { - if (fsBuf != NULL) { - free(fsBuf); - } - fsBuf = malloc((fsCountOrig + 1) * sizeof(*fsBuf)); - if (fsBuf == NULL) { - err = ENOMEM; - } - } - - // Get the list. - if (err == 0) { - fsCount = getfsstat(fsBuf, (int) ((fsCountOrig + 1) * sizeof(*fsBuf)), MNT_WAIT); - if (fsCount < 0) { - err = errno; - } - } - - // We got the full list if the number of items returned by the kernel - // is strictly less than the buffer that we allocated (fsCountOrig + 1). - if (err == 0) { - if (fsCount <= fsCountOrig) { - done = true; - } - } - } while ( (err == 0) && ! done ); - - int i; - int mountCounts = 0; - for (i = 0; i < fsCount; i++) { - if ((fsBuf[i].f_flags & MNT_LOCAL) == 0 || (fsBuf[i].f_flags & MNT_JOURNALED) == 0) { - if (mountCounts == 0) { - printf("UNWATCHEABLE\n"); - } - printf("%s\n", fsBuf[i].f_mntonname); - mountCounts++; - } - } - - if (mountCounts > 0) { - printf("#\n"); - fflush(stdout); - } - - free(fsBuf); - fsBuf = NULL; - - return err; -} - -void callback(ConstFSEventStreamRef streamRef, - void *clientCallBackInfo, - size_t numEvents, - void *eventPaths, - const FSEventStreamEventFlags eventFlags[], - const FSEventStreamEventId eventIds[]) { +static void callback(ConstFSEventStreamRef streamRef, + void *clientCallBackInfo, + size_t numEvents, + void *eventPaths, + const FSEventStreamEventFlags eventFlags[], + const FSEventStreamEventId eventIds[]) { char **paths = eventPaths; - - int i; - for (i=0; i= mountLen && strncmp(root, mount, mountLen) == 0) { + // root under mount point + if (rootLen == mountLen || root[mountLen] == '/' || strcmp(mount, "/") == 0) { + printf("%s\n", root); + } + } + else if (strncmp(root, mount, rootLen) == 0) { + // root over mount point + if (strcmp(root, "/") == 0 || mount[rootLen] == '/') { + printf("%s\n", mount); + } + } + } + } } - ReportMountedFileSystems(); + printf("#\n"); + fflush(stdout); +} - pthread_t thread_id; - int rc = pthread_create(&thread_id, NULL, event_processing_thread, NULL); +static void ParseRoots() { + CFMutableArrayRef roots = CFArrayCreateMutable(NULL, 0, NULL); - if (rc != 0) { - // Give up if cannot create a thread. - printf("GIVEUP\n"); - exit(1); + while (TRUE) { + fscanf(stdin, "%s", command); + if (strcmp(command, "#") == 0 || feof(stdin)) break; + char* path = command[0] == '|' ? command + 1 : command; + CFArrayAppendValue(roots, strdup(path)); + } + + PrintMountedFileSystems(roots); + + for (int i = 0; i < CFArrayGetCount(roots); i++) { + void *value = (char *)CFArrayGetValueAtIndex(roots, i); + free(value); + } + CFRelease(roots); +} + +int main(const int argc, const char* argv[]) { + // Checking if necessary API is available (need MacOS X 10.5 or later). + if (FSEventStreamCreate == NULL) { + printf("GIVEUP\n"); + return 1; + } + + pthread_t threadId; + if (pthread_create(&threadId, NULL, EventProcessingThread, NULL) != 0) { + // Give up if cannot create a thread. + printf("GIVEUP\n"); + return 2; } while (TRUE) { - fscanf(stdin, "%s", command); - if (strcmp(command, "EXIT") == 0 || feof(stdin)) exit(0); - if (strcmp(command, "ROOTS") == 0) parseRoots(); + fscanf(stdin, "%s", command); + if (strcmp(command, "EXIT") == 0 || feof(stdin)) break; + if (strcmp(command, "ROOTS") == 0) ParseRoots(); } - + return 0; } diff --git a/native/fsNotifier/mac/make.sh b/native/fsNotifier/mac/make.sh index 3122301a098e..1810f1b60efa 100755 --- a/native/fsNotifier/mac/make.sh +++ b/native/fsNotifier/mac/make.sh @@ -1,2 +1,3 @@ #!/bin/sh -gcc -arch i386 -mmacosx-version-min=10.5 -framework CoreServices -o fsnotifier fsnotifier.c +# Clang can be downloaded from from http://llvm.org/releases/download.html or found in XCode 4+ +clang -arch i386 -mmacosx-version-min=10.5 -framework CoreServices -o fsnotifier fsnotifier.c