3 //<script type="text/javascript">
4 // silly test to see how libc works :)
5 // borked - inotify sends a struct via a buffer -- need to use inotify tools!
6 inotifytools = imports.gi.inotifytools;
7 GLib = imports.gi.GLib;
13 if (!inotifytools.initialize()) {
14 Seed.print("Failed to init");
17 Seed.print("watch Error?" + GLib.strerror(inotifytools.error()));
18 var events = inotifytools.IN_ACCESS |
19 inotifytools.IN_MODIFY |
20 inotifytools.IN_ATTRIB |
21 inotifytools.IN_CLOSE_WRITE |
22 inotifytools.IN_CLOSE_NOWRITE |
23 inotifytools.IN_OPEN |
24 inotifytools.IN_MOVED_FROM |
25 inotifytools.IN_MOVED_TO |
26 inotifytools.IN_DELETE |
27 inotifytools.IN_CREATE |
28 inotifytools.IN_DELETE_SELF |
29 inotifytools.IN_MOVE_SELF;
30 print("EVENTS:"+ events);
31 var dir = String(Seed.argv[2])
32 Seed.print("MONITOR: " + dir +"?");
33 var r = inotifytools.watch_recursively( dir , events);
35 Seed.print("GOT " +r );
37 Seed.print("watch Error?" + GLib.strerror(inotifytools.error()));
42 var num_watches = inotifytools.get_num_watches();
43 Seed.print("Watch " + num_watches );
47 var event = inotifytools.next_event( 0 );
48 Seed.print(event.len);
49 inotifytools.printf(event, "in %w, file %f had event(s): %.e\n");
52 if ( !inotifytools.error() ) {
53 Seed.print("Timeout?");
56 else if ( inotifytools.error() != 4 ) {
57 Seed.print("Error?" + inotifytools.error());
64 if ( moved_from.length && !(event.mask & inotifytools.IN_MOVED_TO) ) {
65 if ( !inotifytools.remove_watch_by_filename( moved_from ) ) {
66 Seed.print( "Error removing watch on " + moved_from );
71 if ((event.mask & inotifytools.IN_CREATE) ||
72 (!moved_from.length && (event.mask & inotifytools.IN_MOVED_TO))) {
73 // New file - if it is a directory, watch it
76 var new_file = inotifytools.filename_from_wd( event.wd ) + event.name ;
78 if ( GLib.file_test(new_file, GLib.FileTest.IS_DIR) &&
79 !inotifytools.watch_recursively( new_file, events ) ) {
80 Seed.print( "Couldn't watch new directory " + new_file);
84 else if (event.mask & inotifytools.IN_MOVED_FROM) {
85 moved_from = inotifytools.filename_from_wd( event.wd ) + event.name ;
87 if ( inotifytools.wd_from_filename(moved_from) == -1 ) {
91 else if (event.mask & inotifytools.IN_MOVED_TO) {
92 if ( moved_from.length ) {
93 var new_name = inotifytools_filename_from_wd( event. wd ) +
95 inotifytools.replace_filename( moved_from, new_name );
100 Seed.print("CHANGE" + inotifytools.event_to_str(event.mask) + "\n" +
101 inotifytools.filename_from_wd( event.wd ) + event.name + "\n");