Try to make missing pidfile and logfile parent dir
authorJeremy Stanley <fungi@yuggoth.org>
Sat, 27 Oct 2018 20:52:04 +0000 (20:52 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Sat, 27 Oct 2018 20:52:04 +0000 (20:52 +0000)
Rather than assume the path to a specified pidfile or logfile
already exists, try to make it before opening the file for writing.
This solves an issue with `tox -e debug` raising FileNotFoundError
when trying to open the logfile. Remove the mkdir() call in the
selftest setup so that this gets exercised properly.

mudpy/misc.py
mudpy/tests/selftest.py

index 7698e81..f4168ee 100644 (file)
@@ -994,6 +994,7 @@ def log(message, level=0):
     if file_name:
         if not os.path.isabs(file_name):
             file_name = os.path.join(universe.startdir, file_name)
+        os.makedirs(os.path.dirname(file_name), exist_ok=True)
         file_descriptor = codecs.open(file_name, "a", "utf-8")
         for line in lines:
             file_descriptor.write(timestamp + " " + line + "\n")
@@ -2389,6 +2390,7 @@ def create_pidfile(universe):
     if file_name:
         if not os.path.isabs(file_name):
             file_name = os.path.join(universe.startdir, file_name)
+        os.makedirs(os.path.dirname(file_name), exist_ok=True)
         file_descriptor = codecs.open(file_name, "w", "utf-8")
         file_descriptor.write(pid + "\n")
         file_descriptor.flush()
index c3c5dea..40ea0f3 100644 (file)
@@ -347,7 +347,6 @@ def start_service(config):
         os.remove(f.name)
     for d in ("data", "var"):
         shutil.rmtree(d, ignore_errors=True)
-    os.mkdir("var")
 
     # Start the service and wait for it to be ready for connections
     service = subprocess.Popen(("mudpy", config),