aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-02-06 01:45:26 -0600
committerthe lemons <citrons@mondecitronne.com>2022-02-06 01:45:26 -0600
commita75c8e0a8bc6a1ef3e5b1e90d45ec5e99765192a (patch)
tree5857e532582997bac093113c301f07c95c5925f6
parentd15752fccafaa6ee358f508d7bb10ae7efc0fa57 (diff)
if name exists, generate new one
-rwxr-xr-xzzcxz.cgi8
1 files changed, 7 insertions, 1 deletions
diff --git a/zzcxz.cgi b/zzcxz.cgi
index ea9cab0..d5a62b6 100755
--- a/zzcxz.cgi
+++ b/zzcxz.cgi
@@ -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'))