diff options
author | the lemons <citrons@mondecitronne.com> | 2022-02-06 01:45:26 -0600 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2022-02-06 01:45:26 -0600 |
commit | a75c8e0a8bc6a1ef3e5b1e90d45ec5e99765192a (patch) | |
tree | 5857e532582997bac093113c301f07c95c5925f6 | |
parent | d15752fccafaa6ee358f508d7bb10ae7efc0fa57 (diff) |
if name exists, generate new one
-rwxr-xr-x | zzcxz.cgi | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -254,12 +254,18 @@ local function new_action(page, action, result) return directives.redirect end +::generate_name:: local new_name = {} for i=1,5 do table.insert(new_name, string.char(string.byte 'a' + math.random(0,25))) end new_name = table.concat(new_name) - assert(not io.open('content/'..new_name, 'r'), "page already exists!") + + local exists = io.open('content/'..new_name, 'r') + if exists then + exists:close() + goto generate_name + end local new = assert(io.open('content/'..new_name, 'w')) |