X-Git-Url: http://git.roojs.org/?p=gitlive;a=blobdiff_plain;f=Monitor.vala;h=b8e3bced5af31644aac55c3c2d0bb61437960309;hp=99cf199e068df5c2e89573e4559a65e195539f41;hb=refs%2Fheads%2Fwip_alan_T5639_gitlive_general_tidy_ups;hpb=6d6a89f4ff4b5cbcf50ceba7b451730e1e8e0f47 diff --git a/Monitor.vala b/Monitor.vala index 99cf199e..b8e3bced 100644 --- a/Monitor.vala +++ b/Monitor.vala @@ -68,7 +68,12 @@ public delegate void onEventHander (FileMonitor fm, File f_orig, File of_orig, F * */ -public class Monitor : Object +public abstract class gitMonitorBase : Object +{ + public abstract void monitor(string path, int depth = 0); +} + +public class Monitor : gitMonitorBase { @@ -136,10 +141,10 @@ public class Monitor : Object * * */ - public void monitor(string path, int depth = 0) + public override void monitor(string path, int depth = 0) { - stdout.printf("ADD: (%d): %s\n", depth, path); + //GLib.debug("ADD: (%d): %s\n", depth, path); //depth = typeof(depth) == 'number' ? depth *1 : 0; depth = depth > 0 ? depth *1 : 0; @@ -148,20 +153,21 @@ public class Monitor : Object //fn = fn || function (fm, f, of, event_type, uh) { // _this.onEvent(fm, f, of, event_type, uh); //} - - + var f = File.new_for_path(path); //var cancel = new Gio.Cancellable (); if (depth > 0) { try { - - var fm = f.monitor(FileMonitorFlags.SEND_MOVED,null); //Gio.FileMonitorFlags.SEND_MOVED + var fm = f.monitor(FileMonitorFlags.SEND_MOVED + FileMonitorFlags.WATCH_MOVES,null); + //var fm = f.monitor(FileMonitorFlags.WATCH_MOVES,null); fm.changed.connect( this.onEvent ); this.monitors.append_val(fm); } catch (Error e) { + GLib.debug("Error adding monitor: %s\n", e.message); + GLib.debug("Try: \n\nsudo su\necho 512 > /proc/sys/fs/inotify/max_user_instances\n"); // FIXME -- show error? do nothing.. } // print("ADD path " + depth + ' ' + path); @@ -275,25 +281,9 @@ public class Monitor : Object MonitorNamePathDir src = new MonitorNamePathDir( f.get_basename(), f.get_path() , Path.get_dirname(f.get_path())); - - - - //string event_name = "UKNOWN"; - - - // extract the event names ... - not sure if introspection is feasible in vala.. - //for(var i in Gio.FileMonitorEvent) { - // if (Gio.FileMonitorEvent[i] == event_type) { - // event_name = i; - // } - //} - - - - - //print (JSON.stringify([event_name , f.get_path(), of ? of.get_path() : false ] )); - //print ("got src: " + src.toString()); - //print ("got event: " + src.toString()); + + GLib.debug("onEvent src: %s", f.get_path()); + try { @@ -324,19 +314,32 @@ public class Monitor : Object return; case FileMonitorEvent.MOVED: // eg. chmod/chatt - - var of = this.realpath(of_orig); - var dest = new MonitorNamePathDir( - of.get_basename(), - of.get_path(), - Path.get_dirname(of.get_path()) - ); - - + case FileMonitorEvent.MOVED_IN: // eg. chmod/chatt + case FileMonitorEvent.MOVED_OUT: // eg. chmod/chatt + case FileMonitorEvent.RENAMED: // eg. chmod/chatt + if (of_orig == null) { // move from outside of monitoring? + this.onChanged(src); + return; + } + + + var of = this.realpath(of_orig); + var dest = new MonitorNamePathDir( + of.get_basename(), + of.get_path(), + Path.get_dirname(of.get_path()) + ); + + if (dest == null) { + + return; + } src.action = "moved"; dest.action = "moved"; this.onMoved(src,dest); return; + + default: stdout.printf("event type not handled %u", event_type); break;