Refuse to re upload existing file

This commit is contained in:
Benoit Calvez 2012-09-17 16:50:25 +02:00
parent 5cb109515c
commit b8c775c4d7
2 changed files with 10 additions and 4 deletions

View File

@ -110,7 +110,9 @@ def update():
if "/" in content.filename:
raise HTTPError(400, output="bad filename")
packages.store(content.filename, content.value)
if not packages.store(content.filename, content.value):
raise HTTPError(409, output="file already exists")
return ""

View File

@ -68,10 +68,14 @@ class pkgset(object):
def store(self, filename, data):
assert "/" not in filename
dest_fn = os.path.join(self.root, filename)
dest_fh = open(dest_fn, "wb")
if not os.path.exists(dest_fn):
dest_fh = open(dest_fn, "wb")
dest_fh.write(data)
dest_fh.close()
dest_fh.write(data)
dest_fh.close()
return True
return False
def usage():