Linux fsnotifier output buffering fixed; cleanup

This commit is contained in:
Roman Shevchenko
2013-01-20 22:49:14 +04:00
parent 1f6276d8aa
commit 9c32480c05
5 changed files with 11 additions and 7 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -104,7 +104,6 @@ int main(int argc, char** argv) {
}
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
roots = array_create(20);
if (init_inotify() && roots != NULL) {
@@ -120,7 +119,7 @@ int main(int argc, char** argv) {
unregister_roots();
}
else {
printf("GIVEUP\n");
output("GIVEUP\n");
}
close_inotify();
array_delete(roots);
@@ -430,7 +429,7 @@ static void report_event(char* event, char* path) {
userlog(LOG_DEBUG, "%s: %s", event, path);
int len = strlen(path);
for (char* p = path; *p != '\0'; p++){
for (char* p = path; *p != '\0'; p++) {
if (*p == '\n') {
*p = '\0';
}
@@ -440,6 +439,8 @@ static void report_event(char* event, char* path) {
fputc('\n', stdout);
fwrite(path, len, 1, stdout);
fputc('\n', stdout);
fflush(stdout);
}
@@ -452,4 +453,6 @@ static void output(const char* format, ...) {
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
fflush(stdout);
}

View File

@@ -24,7 +24,7 @@ static void reportEvent(char *event, char *path) {
int len = 0;
if (path != NULL) {
len = strlen(path);
for (char* p = path; *p != '\0'; p++){
for (char* p = path; *p != '\0'; p++) {
if (*p == '\n') {
*p = '\0';
}

View File

@@ -176,9 +176,9 @@ public class FileWatcher {
private static boolean isUpToDate(File executable) {
long length = SystemInfo.isWindows ? 70216 :
SystemInfo.isMac ? 13924 :
SystemInfo.isLinux ? SystemInfo.isAMD64 ? 29296 : 22793 :
SystemInfo.isLinux ? SystemInfo.isAMD64 ? 29308 : 22809 :
-1;
return length > 0 && length == executable.length();
return length < 0 || length == executable.length();
}
private void notifyOnFailure(final String cause, @Nullable final NotificationListener listener) {
@@ -474,7 +474,8 @@ public class FileWatcher {
}
}
else {
processChange(line.replace('\0', '\n'), myLastOp);
String path = line.replace('\0', '\n'); // unescape
processChange(path, myLastOp);
myLastOp = null;
}
}