From b8bc4fc22157f43c15f40d784ab05bdd30c93c44 Mon Sep 17 00:00:00 2001 From: Marius Date: Sat, 5 May 2012 12:00:16 +0300 Subject: beta 2012.05.05 10:42 --- scripts/context/lua/mtx-watch.lua | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-watch.lua b/scripts/context/lua/mtx-watch.lua index 5bd0ad5f4..118d1a815 100644 --- a/scripts/context/lua/mtx-watch.lua +++ b/scripts/context/lua/mtx-watch.lua @@ -30,6 +30,8 @@ scripts.watch = scripts.watch or { } local format, concat, difftime, time = string.format, table.concat, os.difftime, os.time local next, type = next, type +local basename, dirname, joinname = file.basename, file.dirname, file.join +local lfsdir, lfsattributes = lfs.dir, lfs.attributes -- the machine/instance matches the server app we use @@ -68,9 +70,10 @@ local function noset(t) end end -local lfsdir, lfsattributes = lfs.dir, lfs.attributes -local function glob(files,path) +-- todo: split order (o-name.luj) and combine with atime to determine sort order. + +local function glob(files,path) -- some day: sort by name (order prefix) and atime for name in lfsdir(path) do if name:find("^%.") then -- skip . and .. @@ -86,7 +89,8 @@ local function glob(files,path) glob(files,name) end elseif name:find(".%luj$") then - files[name] = a.change or a.ctime or a.modification or a.mtime + -- files[name] = a.change or a.ctime or a.modification or a.mtime + files[#files+1] = { dirname(name), basename(name) } end end end @@ -94,6 +98,16 @@ end local clock = os.gettimeofday or os.time -- we cannot trust os.clock on linux +local function filenamesort(a,b) + local fa, da = a[1], a[2] + local fb, db = b[1], b[2] + if da == db then + return fa < fb + else + return da < db + end +end + function scripts.watch.watch() local delay = tonumber(environment.argument("delay") or 5) or 5 if delay == 0 then @@ -120,8 +134,13 @@ function scripts.watch.watch() lfs.chdir(path) local files = { } glob(files,path) - table.sort(files) -- what gets sorted here, todo: by time - for name, time in next, files do + table.sort(files,filenamesort) +-- for name, time in next, files do + for i=1,#files do + local f = files[i] + local dirname = f[1] + local basename = f[2] -- we can use that later on + local name = joinname(dirname,basename) --~ local ok, joblog = xpcall(function() return dofile(name) end, function() end ) local ok, joblog = pcall(dofile,name) if ok and joblog then -- cgit v1.2.3