From 2ad5fd0e51ec4f882483495fb21d944530028dca Mon Sep 17 00:00:00 2001 From: Haly Date: Tue, 28 Jun 2022 01:16:04 +0800 Subject: [PATCH] semihosting: ensure directories exist before open file for writing (#1407) --- pyocd/debug/semihost.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyocd/debug/semihost.py b/pyocd/debug/semihost.py index 16cc85c87..5e111fe42 100644 --- a/pyocd/debug/semihost.py +++ b/pyocd/debug/semihost.py @@ -1,5 +1,6 @@ # pyOCD debugger # Copyright (c) 2015-2020 Arm Limited +# Copyright (c) 2022 NXP # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +21,7 @@ import logging import time import datetime +import pathlib import six from ..coresight.cortex_m import CortexM @@ -184,6 +186,10 @@ def open(self, fnptr, fnlen, mode): return fd try: + # ensure directories are exists if mode is write/appened + if ('w' in mode) or ('a' in mode): + pathlib.Path(filename).parent.mkdir(parents=True, exist_ok=True) + fd = self.next_fd self.next_fd += 1