local plain = {} function plain.commit(file_uwiki, file_temp, message) --First we separate file and dir local dir,file = string.match(file_uwiki,"^(.*)/(.-)$") local backup= dir .. "~" .. file) if not file_copy(file_temp, file_uwiki) then --Delete backup, make a backup and delete original file_delete(backup) file_copy(file_uwiki,backup) file_delete(file_uwiki) --The we can copy the new file file_copy(file_temp, file_uwiki) end end function plain.show_log(file) t = {} return t end --Get a md5sum for a given file function plain.identify(file) local temp_file=os.tmpname() os.execute("md5sum " .. file .. " > " .. temp_file) io.input(temp_file) local s = io.read("*line") s=string.match(s, "(.*) .*") os.remove(temp_file) return t end function plain.save(file_temp, file_uwiki, old_checksum, message) --Make a checksum of the file in the server new_checksum=plain.identify(file_uwiki) --If the file in the server has not been modified --since the user started editing if old_checksum == new_checksum then --We can commit plain.commit(file_uwiki, file_temp, message) else --First we separate file and dir local dir,file = string.match(file_uwiki,"^(.*)/(.-)$") local backup= dir .. "~" .. file) --Check if we have a backup if (file_exists(backup) then --We can do a three way merge threewaymerge(file_uwiki, backup, file_temp) else merge_manually(file_uwiki, file_temp) end end end return plain