diff options
author | mpeterv <mpeterval@gmail.com> | 2016-04-17 15:16:30 +0300 |
---|---|---|
committer | mpeterv <mpeterval@gmail.com> | 2016-04-17 15:19:26 +0300 |
commit | 73874505c05821494b79272e4e092ba86e20c39e (patch) | |
tree | df3b8537fcc9abd1a5d0af0b25f1854b63ec4019 | |
parent | e5acbfe702183a8e19527b8e299f4f5bc08b930f (diff) | |
download | luacov-73874505c05821494b79272e4e092ba86e20c39e.tar.gz |
Don't clear statsfile after loading from it
Don't drop old stats if the program crashes without triggering
exit hooks after loading.
TODO: convert stats file name to absolute on config load
so that changing directories doesn't break stats saving.
-rw-r--r-- | src/luacov/runner.lua | 8 | ||||
-rw-r--r-- | src/luacov/stats.lua | 22 |
2 files changed, 5 insertions, 25 deletions
diff --git a/src/luacov/runner.lua b/src/luacov/runner.lua index 140f314..48d7ba7 100644 --- a/src/luacov/runner.lua +++ b/src/luacov/runner.lua @@ -21,7 +21,6 @@ local function on_exit_wrap(fn) end local data -local statsfile local tick local paused = true local initialized = false @@ -386,8 +385,7 @@ function runner.pause() end paused = true - stats.save(data, statsfile) - stats.stop(statsfile) + stats.save(data) -- Reset data, so that after resuming it could be added to data loaded -- from the stats file, possibly updated from another process. data = {} @@ -416,10 +414,6 @@ function runner.resume() data = loaded end - statsfile = stats.start() - runner.statsfile = statsfile - - if not tick then -- As __gc hooks are called in reverse order of their creation, -- and stats file has a __gc hook closing it, diff --git a/src/luacov/stats.lua b/src/luacov/stats.lua index 30a7a48..526d974 100644 --- a/src/luacov/stats.lua +++ b/src/luacov/stats.lua @@ -55,25 +55,11 @@ function stats.load() end -------------------------------- --- Opens the statfile --- @return filehandle -function stats.start() - return io.open(stats.statsfile, "w") -end - --------------------------------- --- Closes the statfile --- @param fd filehandle to the statsfile -function stats.stop(fd) - fd:close() -end - --------------------------------- -- Saves data to the statfile -- @param data data to store --- @param fd filehandle where to store -function stats.save(data, fd) - fd:seek("set") +function stats.save(data) + local fd = io.open(stats.statsfile, "w") + for filename, filedata in pairs(data) do local max = filedata.max fd:write(max, ":", filename, "\n") @@ -86,7 +72,7 @@ function stats.save(data, fd) end fd:write("\n") end - fd:flush() + fd:close() end return stats |