Skip to content

Commit

Permalink
semihosting: ensure directories exist before open file for writing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoohaha authored and flit committed Oct 23, 2022
1 parent 8caa8bd commit 2ad5fd0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pyocd/debug/semihost.py
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -20,6 +21,7 @@
import logging
import time
import datetime
import pathlib
import six

from ..coresight.cortex_m import CortexM
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2ad5fd0

Please sign in to comment.