Make sure we don't try to read when opening a file in binary more. Fixes #1301.

This commit is contained in:
grossmj committed 2018-03-07 16:39:04 +07:00
1 parent 419797dd92
commit c93d0d8d12
8 files changed
+36 -26

No files matched your search

@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import aiohttp
from gns3server.web.route import Route
from gns3server.controller import Controller
@@ -62,12 +63,15 @@ class SymbolHandler:
def upload(request, response):
controller = Controller.instance()
path = os.path.join(controller.symbols.symbols_path(), os.path.basename(request.match_info["symbol_id"]))
with open(path, 'wb+') as f:
while True:
packet = yield from request.content.read(512)
if not packet:
break
f.write(packet)
try:
with open(path, 'wb') as f:
while True:
packet = yield from request.content.read(512)
if not packet:
break
f.write(packet)
except OSError as e:
raise aiohttp.web.HTTPConflict(text="Could not write symbol file '{}': {}".format(path, e))
# Reset the symbol list
controller.symbols.list()
response.set_status(204)