mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-02-07 08:43:48 +02:00
Make sure we don't try to read when opening a file in binary more. Fixes #1301.
This commit is contained in:
parent
419797dd92
commit
c93d0d8d12
@ -549,7 +549,7 @@ class BaseManager:
|
|||||||
# We store the file under his final name only when the upload is finished
|
# We store the file under his final name only when the upload is finished
|
||||||
tmp_path = path + ".tmp"
|
tmp_path = path + ".tmp"
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
with open(tmp_path, 'wb+') as f:
|
with open(tmp_path, 'wb') as f:
|
||||||
while True:
|
while True:
|
||||||
packet = yield from stream.read(4096)
|
packet = yield from stream.read(4096)
|
||||||
if not packet:
|
if not packet:
|
||||||
|
@ -547,7 +547,7 @@ class Dynamips(BaseManager):
|
|||||||
content = content.replace('%h', vm.name)
|
content = content.replace('%h', vm.name)
|
||||||
f.write(content.encode("utf-8"))
|
f.write(content.encode("utf-8"))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise DynamipsError("Could not create config file {}: {}".format(path, e))
|
raise DynamipsError("Could not create config file '{}': {}".format(path, e))
|
||||||
|
|
||||||
return os.path.join("configs", os.path.basename(path))
|
return os.path.join("configs", os.path.basename(path))
|
||||||
|
|
||||||
|
@ -348,14 +348,14 @@ class IOUVM(BaseNode):
|
|||||||
# reload
|
# reload
|
||||||
path = os.path.join(os.path.expanduser("~/"), ".iourc")
|
path = os.path.join(os.path.expanduser("~/"), ".iourc")
|
||||||
try:
|
try:
|
||||||
with open(path, "wb+") as f:
|
with open(path, "wb") as f:
|
||||||
f.write(value.encode("utf-8"))
|
f.write(value.encode("utf-8"))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise IOUError("Could not write the iourc file {}: {}".format(path, e))
|
raise IOUError("Could not write the iourc file {}: {}".format(path, e))
|
||||||
|
|
||||||
path = os.path.join(self.temporary_directory, "iourc")
|
path = os.path.join(self.temporary_directory, "iourc")
|
||||||
try:
|
try:
|
||||||
with open(path, "wb+") as f:
|
with open(path, "wb") as f:
|
||||||
f.write(value.encode("utf-8"))
|
f.write(value.encode("utf-8"))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise IOUError("Could not write the iourc file {}: {}".format(path, e))
|
raise IOUError("Could not write the iourc file {}: {}".format(path, e))
|
||||||
|
@ -118,7 +118,7 @@ class Drawing:
|
|||||||
|
|
||||||
file_path = os.path.join(self._project.pictures_directory, filename)
|
file_path = os.path.join(self._project.pictures_directory, filename)
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
with open(file_path, "wb+") as f:
|
with open(file_path, "wb") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
value = filename
|
value = filename
|
||||||
|
|
||||||
|
@ -315,16 +315,19 @@ class Link:
|
|||||||
self._project.controller.notification.emit("link.updated", self.__json__())
|
self._project.controller.notification.emit("link.updated", self.__json__())
|
||||||
|
|
||||||
with stream_content as stream:
|
with stream_content as stream:
|
||||||
with open(self.capture_file_path, "wb+") as f:
|
try:
|
||||||
while self._capturing:
|
with open(self.capture_file_path, "wb") as f:
|
||||||
# We read 1 bytes by 1 otherwise the remaining data is not read if the traffic stops
|
while self._capturing:
|
||||||
data = yield from stream.read(1)
|
# We read 1 bytes by 1 otherwise the remaining data is not read if the traffic stops
|
||||||
if data:
|
data = yield from stream.read(1)
|
||||||
f.write(data)
|
if data:
|
||||||
# Flush to disk otherwise the live is not really live
|
f.write(data)
|
||||||
f.flush()
|
# Flush to disk otherwise the live is not really live
|
||||||
else:
|
f.flush()
|
||||||
break
|
else:
|
||||||
|
break
|
||||||
|
except OSError as e:
|
||||||
|
raise aiohttp.web.HTTPConflict(text="Could not write capture file '{}': {}".format(self.capture_file_path, e))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def stop_capture(self):
|
def stop_capture(self):
|
||||||
|
@ -627,9 +627,12 @@ class Project:
|
|||||||
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
||||||
with open(snapshot.path, "wb+") as f:
|
try:
|
||||||
for data in zipstream:
|
with open(snapshot.path, "wb") as f:
|
||||||
f.write(data)
|
for data in zipstream:
|
||||||
|
f.write(data)
|
||||||
|
except OSError as e:
|
||||||
|
raise aiohttp.web.HTTPConflict(text="Could not write snapshot file '{}': {}".format(snapshot.path, e))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
|
raise aiohttp.web.HTTPInternalServerError(text="Could not create project directory: {}".format(e))
|
||||||
|
|
||||||
@ -858,7 +861,7 @@ class Project:
|
|||||||
try:
|
try:
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
zipstream = yield from export_project(self, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
||||||
with open(os.path.join(tmpdir, "project.gns3p"), "wb+") as f:
|
with open(os.path.join(tmpdir, "project.gns3p"), "wb") as f:
|
||||||
for data in zipstream:
|
for data in zipstream:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
with open(os.path.join(tmpdir, "project.gns3p"), "rb") as f:
|
with open(os.path.join(tmpdir, "project.gns3p"), "rb") as f:
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import aiohttp
|
||||||
from gns3server.web.route import Route
|
from gns3server.web.route import Route
|
||||||
from gns3server.controller import Controller
|
from gns3server.controller import Controller
|
||||||
|
|
||||||
@ -62,12 +63,15 @@ class SymbolHandler:
|
|||||||
def upload(request, response):
|
def upload(request, response):
|
||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
path = os.path.join(controller.symbols.symbols_path(), os.path.basename(request.match_info["symbol_id"]))
|
path = os.path.join(controller.symbols.symbols_path(), os.path.basename(request.match_info["symbol_id"]))
|
||||||
with open(path, 'wb+') as f:
|
try:
|
||||||
while True:
|
with open(path, 'wb') as f:
|
||||||
packet = yield from request.content.read(512)
|
while True:
|
||||||
if not packet:
|
packet = yield from request.content.read(512)
|
||||||
break
|
if not packet:
|
||||||
f.write(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
|
# Reset the symbol list
|
||||||
controller.symbols.list()
|
controller.symbols.list()
|
||||||
response.set_status(204)
|
response.set_status(204)
|
||||||
|
@ -160,7 +160,7 @@ def pid_lock(path):
|
|||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
try:
|
try:
|
||||||
pid = int(f.read())
|
pid = int(f.read())
|
||||||
os.kill(pid, 0) # If the proces is not running kill return an error
|
os.kill(pid, 0) # kill returns an error if the process is not running
|
||||||
except (OSError, SystemError, ValueError):
|
except (OSError, SystemError, ValueError):
|
||||||
pid = None
|
pid = None
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user