From 42b31c4760195e369046af91d3406387547691ab Mon Sep 17 00:00:00 2001 From: assar Date: Sat, 10 Jun 2017 14:34:56 +0200 Subject: [PATCH] Avoiding same-name datasheet files --- server.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server.py b/server.py index 1f617d2..3d3231f 100644 --- a/server.py +++ b/server.py @@ -73,6 +73,10 @@ def alter(partID): if len(request.files) != 0: datasheet_file = request.files['datasheet-file'] datasheet_filename = secure_filename(datasheet_file.filename) + i = 1 + while os.path.isfile('srv/datasheet/' + datasheet_filename): + datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' + i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) else: datasheet_filename = None @@ -97,6 +101,10 @@ def alter(partID): if len(request.files) != 0: datasheet_file = request.files['datasheet-file'] datasheet_filename = secure_filename(datasheet_file.filename) + i = 1 + while os.path.isfile('srv/datasheet/' + datasheet_filename): + datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' + i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) if l[0]['datasheet'] != None: os.remove('/srv/datasheets/' + l[0]['datasheet'])