irongit

Configure synchronization of files and directories through a plugin.

rock solid working with files now too

huncholanehuncholaneauthored
parent b09af24commit 1526553f94787b8485c9f7dc86829de666ef7f6bBrowse files

2 files changed, +20 -9

+8-5lua/syncmap/rsync.lua
@@ -35,12 +35,16 @@ function M.spawn_watcher(args)
3535 end
3636
3737 local cmd = "while inotifywait "
38- if vim.uv.fs_stat(args.src).type == "directory" then
38+ local stat = vim.uv.fs_stat(args.src)
39+ if stat and stat.type == "directory" then
3940 log.debug(string.format("Setting up inotify for a file.\n%s", args.src))
4041 cmd = cmd .. string.format("-r -e modify,create,delete %q; ", args.src)
41- else
42+ elseif stat and stat.type == "file" then
4243 log.debug(string.format("Setting up inotify for a file.\n%s", args.src))
43- cmd = cmd .. string.format("-e %q; ", args.src)
44+ cmd = cmd .. string.format("-e modify %q; ", args.src)
45+ else
46+ log.error(string.format("Could not stat %s", args.src))
47+ return "NO STAT"
4448 end
4549 cmd = cmd .. string.format("do rsync %s %q %q; done", table.concat(args.flags, " "), args.src, args.dst)
4650 local cmd_str_for_log = "sh -c '" .. cmd .. "'"
@@ -48,7 +52,6 @@ function M.spawn_watcher(args)
4852 local handle, pid = simple_cmd.spawn("sh", {
4953 args = { "-c", cmd },
5054 path = "sh",
51- -- cwd = args.src,
5255 callback = function(code, status, _, pid)
5356 log.debug(string.format("%s\n%d completed with %d code and %d status", cmd_str_for_log, pid, code, status))
5457 end,
@@ -58,7 +61,7 @@ function M.spawn_watcher(args)
5861 else
5962 log.debug(string.format("Started the following command with pid %d\n%s", pid, cmd_str_for_log))
6063 end
61- return pid
64+ return pid, cmd_str_for_log
6265 end
6366
6467 return M
+12-4lua/syncmap/state.lua
@@ -69,11 +69,13 @@ function M.sync()
6969 elseif not simple_cmd.exists(pid) then
7070 local m = lookup[tag]
7171 local r = utils.row_to_rsync_params(m)
72- M.active[tag] = rsync.spawn_watcher(r)
72+ local cmd_str
73+ M.active[tag], cmd_str = rsync.spawn_watcher(r)
7374 log.info(
7475 string.format(
75- "In active table but the process %s is not running.\n%s\nStarting a new process at %s.",
76+ "In active table but the process %s is not running.\n%s\n%s\nStarting a new process at %s.",
7677 pid,
78+ cmd_str,
7779 tag,
7880 M.active[tag]
7981 )
@@ -86,9 +88,15 @@ function M.sync()
8688 local tag = vim.fn.expand(m[1]) .. ":" .. vim.fn.expand(m[2])
8789 if not M.active[tag] then
8890 local r = utils.row_to_rsync_params(m)
89- M.active[tag] = rsync.spawn_watcher(r)
91+ local cmd_str
92+ M.active[tag], cmd_str = rsync.spawn_watcher(r)
9093 log.info(
91- string.format("%s\nIn the config but not in the active table.\nNew process is %s.", tag, M.active[tag])
94+ string.format(
95+ "%s\nIn the config but not in the active table.\n%s\nNew process is %s.",
96+ tag,
97+ cmd_str,
98+ M.active[tag]
99+ )
92100 )
93101 end
94102 end