fuse_kafka
src/handle_file_modified.c
00001 void handle_file_modified(char* path, fk_hash offsets, char* root)
00002 {
00003     char* old_path = path;
00004     if(path == NULL) return;
00005     long int offset = (long int) fk_hash_get(offsets, path, 1);
00006     if(offset == -1)
00007     {
00008         path = strdup(path);
00009         offset = 0;
00010     }
00011     trace_debug("handle_file_modified: File %s modified, offset being %ld.", path, offset);
00012     char* line = 0;
00013     size_t length;
00014     FILE* f = fopen(path, "r");
00015     if(f != NULL)
00016     {
00017         fseek(f, 0, SEEK_END); if(ftell(f) < offset) offset = 0;
00018         fseek(f, offset, SEEK_SET);
00019         ssize_t size;
00020         while((size = getline(&line, &length, f)) > 0)
00021         {
00022             trace_debug("handle_file_modified: File %s, writing %s %d", path, line, size);
00023             output_write(root, path, line, size, 0);
00024         }
00025         if(ftell(f) > offset)
00026         {
00027             trace_debug("handle_file_modified: File %s started reading @%ld, ended @%ld.",
00028                     path, offset, ftell(f));
00029         }
00030         fk_hash_put(offsets, old_path, (void*) ftell(f), 1);
00031         fclose(f);
00032     }
00033     else
00034         if(old_path != path) free(old_path);
00035     free(path);
00036     free(line);
00037 }
00038 
All Data Structures Files Functions Variables Defines