diff options
author | Philipp Gesang <megas.kapaneus@gmail.com> | 2012-10-19 18:44:30 +0200 |
---|---|---|
committer | Philipp Gesang <megas.kapaneus@gmail.com> | 2012-10-19 18:44:30 +0200 |
commit | e9578dd0f5221aa22d7fc240c3258b05fc213b94 (patch) | |
tree | 82bd601fbc5a67d458080092fd03daf5a10759f3 /lualibs-md5.lua | |
parent | 42d2142a79697299cf42b60d63d8c025d942df36 (diff) | |
download | lualibs-e9578dd0f5221aa22d7fc240c3258b05fc213b94.tar.gz |
update l-md5
Diffstat (limited to 'lualibs-md5.lua')
-rw-r--r-- | lualibs-md5.lua | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lualibs-md5.lua b/lualibs-md5.lua index 27955ef..6abf2e1 100644 --- a/lualibs-md5.lua +++ b/lualibs-md5.lua @@ -7,6 +7,7 @@ if not modules then modules = { } end modules ['l-md5'] = { -- This also provides file checksums and checkers. +local md5, file = md5, file local gsub, format, byte = string.gsub, string.format, string.byte local function convert(str,fmt) @@ -30,17 +31,30 @@ if not md5.dec then function md5.dec(str) return convert(str,"%03i") end end --~ function md5.dec(str) return (gsub(md5.sum(str),".",remap)) end --~ end -file.needs_updating_threshold = 1 - -function file.needs_updating(oldname,newname) -- size modification access change - local oldtime = lfs.attributes(oldname, modification) - local newtime = lfs.attributes(newname, modification) - if newtime >= oldtime then - return false - elseif oldtime - newtime < file.needs_updating_threshold then - return false +function file.needsupdating(oldname,newname,threshold) -- size modification access change + local oldtime = lfs.attributes(oldname,"modification") + if oldtime then + local newtime = lfs.attributes(newname,"modification") + if not newtime then + return true -- no new file, so no updating needed + elseif newtime >= oldtime then + return false -- new file definitely needs updating + elseif oldtime - newtime < (threshold or 1) then + return false -- new file is probably still okay + else + return true -- new file has to be updated + end else - return true + return false -- no old file, so no updating needed + end +end + +file.needs_updating = file.needsupdating + +function file.syncmtimes(oldname,newname) + local oldtime = lfs.attributes(oldname,"modification") + if oldtime and lfs.isfile(newname) then + lfs.touch(newname,oldtime,oldtime) end end @@ -62,7 +76,7 @@ function file.loadchecksum(name) return nil end -function file.savechecksum(name, checksum) +function file.savechecksum(name,checksum) if not checksum then checksum = file.checksum(name) end if checksum then io.savedata(name .. ".md5",checksum) |