]> granicus.if.org Git - esp-idf/commitdiff
confserver: Fix NamedTemporaryFile use on Windows
authorAngus Gratton <angus@espressif.com>
Fri, 16 Aug 2019 09:24:20 +0000 (19:24 +1000)
committerAngus Gratton <gus@projectgus.com>
Fri, 16 Aug 2019 09:24:37 +0000 (19:24 +1000)
Can't have the file open twice, so need to close and delete after reopening.

tools/kconfig_new/confserver.py

index 2e0d24ad7ecc8eb4b3ddfde23db0ea25bb9488c3..cddb572c92208f3036b867d7f459946c7e6cf308 100755 (executable)
@@ -74,12 +74,14 @@ def run_server(kconfig, sdkconfig, sdkconfig_rename, default_version=MAX_PROTOCO
     sdkconfig_renames = [sdkconfig_rename] if sdkconfig_rename else []
     sdkconfig_renames += os.environ.get("COMPONENT_SDKCONFIG_RENAMES", "").split()
     deprecated_options = confgen.DeprecatedOptions(config.config_prefix, path_rename_files=sdkconfig_renames)
-    with tempfile.NamedTemporaryFile(mode='w+b') as f_o:
+    f_o = tempfile.NamedTemporaryFile(mode='w+b', delete=False)
+    try:
         with open(sdkconfig, mode='rb') as f_i:
             f_o.write(f_i.read())
-        f_o.flush()
-        f_o.seek(0)
+        f_o.close()  # need to close as DeprecatedOptions will reopen, and Windows only allows one open file
         deprecated_options.replace(sdkconfig_in=f_o.name, sdkconfig_out=sdkconfig)
+    finally:
+        os.unlink(f_o.name)
     config.load_config(sdkconfig)
 
     print("Server running, waiting for requests on stdin...", file=sys.stderr)