Skip to content

Commit 9d719a0

Browse files
committed
feat: add patched fsnotifier package
1 parent b9c2533 commit 9d719a0

File tree

7 files changed

+1169
-0
lines changed

7 files changed

+1169
-0
lines changed

flake.nix

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
in
1717
{
1818
jetbrains = pkgs.callPackage ./jetbrains { };
19+
fsnotifier = pkgs.callPackage ./fsnotifier { };
1920
}
2021
);
2122

fsnotifier/default.nix

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ lib
2+
, stdenv
3+
, fetchFromGitHub
4+
, fetchpatch
5+
}:
6+
7+
stdenv.mkDerivation rec {
8+
version = "1.0.0";
9+
pname = "fsnotifier";
10+
11+
buildPhase = ''
12+
mkdir -p $out/bin
13+
14+
$CC -O2 -Wall -Wextra -Wpedantic -D "VERSION=\"${version}\"" -std=c11 main.c inotify.c util.c -o fsnotifier
15+
16+
cp fsnotifier $out/bin/fsnotifier
17+
'';
18+
19+
src = ./src;
20+
}

fsnotifier/src/fsnotifier.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
3+
#pragma once
4+
5+
#ifndef VERSION
6+
#define VERSION "SNAPSHOT"
7+
#endif
8+
9+
#define _DEFAULT_SOURCE
10+
#define _FILE_OFFSET_BITS 64
11+
12+
#include <features.h>
13+
14+
#include <stdbool.h>
15+
#include <stdint.h>
16+
#include <stdio.h>
17+
18+
19+
// messaging and logging
20+
void message(const char *text);
21+
22+
enum { LOG_ERR = 0, LOG_WARNING = 1, LOG_INFO = 2 };
23+
void userlog(int priority, const char* format, ...);
24+
25+
#define CHECK_NULL(p, r) if ((p) == NULL) { userlog(LOG_ERR, "out of memory"); return r; }
26+
27+
28+
// variable-length array
29+
typedef struct array_str array;
30+
31+
array* array_create(int initial_capacity);
32+
int array_size(array* a);
33+
void* array_push(array* a, void* element);
34+
void* array_pop(array* a);
35+
void array_put(array* a, int index, void* element);
36+
void* array_get(array* a, int index);
37+
void array_delete(array* a);
38+
void array_delete_vs_data(array* a);
39+
void array_delete_data(array* a);
40+
41+
42+
// poor man's hash table
43+
typedef struct table_str table;
44+
45+
table* table_create(int capacity);
46+
void* table_put(table* t, int key, void* value);
47+
void* table_get(table* t, int key);
48+
void table_delete(table* t);
49+
50+
51+
// inotify subsystem
52+
enum {
53+
ERR_IGNORE = -1,
54+
ERR_CONTINUE = -2,
55+
ERR_ABORT = -3,
56+
ERR_MISSING = -4
57+
};
58+
59+
bool init_inotify(void);
60+
61+
void set_inotify_callback(void (*callback)(const char *, uint32_t));
62+
int get_inotify_fd(void);
63+
int watch(const char* root, array* mounts);
64+
void unwatch(int id, char* path, unsigned int path_len);
65+
bool process_inotify_input(void);
66+
void close_inotify(void);
67+
68+
69+
// reads one line from stream, trims trailing carriage return if any
70+
// returns pointer to the internal buffer (will be overwritten on next call)
71+
char* read_line(FILE* stream);
72+
73+
74+
// path comparison
75+
bool is_parent_path(const char* parent_path, const char* child_path);

0 commit comments

Comments
 (0)