Commit 7d71e4a8 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Don't allow any operation on files that are less than 122 seconds old.

parent 5da883a9
......@@ -10,6 +10,10 @@ sys.path.insert(0, os.path.dirname(__file__))
import mp3wavcfg
# Files modified less than this many seconds ago are hidden from view,
# to ensure we never serve partially written files.
MIN_AGE = 122
def quote(s):
return urllib.parse.quote(s.encode("utf-8"))
......@@ -219,8 +223,11 @@ def sizeof_fmt(num):
def handle_directory(environ, start_response, ph, real_dir):
wavs = {}
mp3s = {}
too_new = {}
dirs = set()
now = time.time()
for fn in os.listdir(real_dir.encode("utf-8")):
fn = fn.decode("utf-8")
......@@ -238,7 +245,10 @@ def handle_directory(environ, start_response, ph, real_dir):
root, ext = os.path.splitext(fn)
if ext == ".wav":
wavs[root] = status
if now - status.st_mtime >= MIN_AGE:
wavs[root] = status
else:
too_new[root] = status
elif ext == ".mp3":
mp3s[root] = status
elif stat.S_ISDIR(status.st_mode):
......@@ -264,6 +274,13 @@ def handle_directory(environ, start_response, ph, real_dir):
res.write("<li>")
res.write("<a href=\"%s/\">%s</a>" % (quote(d), d))
res.write("</li>\n")
for w in sorted(too_new):
res.write("<li>")
res.write(time.strftime("%Y-%m-%d %H:%M:%S ",
time.localtime(too_new[w].st_mtime)))
res.write(w)
res.write(" (Still being written? Please retry soon.)")
res.write("</li>")
for w in sorted(wavs):
res.write("<li>")
res.write(time.strftime("%Y-%m-%d %H:%M:%S",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment