From: Jeremy Stanley Date: Sat, 27 Oct 2018 21:01:52 +0000 (+0000) Subject: Don't LBYL when creating missing data directories X-Git-Tag: 0.0.1~43 X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=commitdiff_plain;h=204ea77ed37ec8bedee7465577106a3ac420523f Don't LBYL when creating missing data directories It's better to ask forgiveness than permission. Just try to create parent directories for any data file, and don't error if they already exist. --- diff --git a/mudpy/data.py b/mudpy/data.py index 25b423b..b73959a 100644 --- a/mudpy/data.py +++ b/mudpy/data.py @@ -111,10 +111,9 @@ class Data: ): # make parent directories if necessary - if not os.path.exists(os.path.dirname(self.source)): - old_umask = os.umask(normal_umask) - os.makedirs(os.path.dirname(self.source)) - os.umask(old_umask) + old_umask = os.umask(normal_umask) + os.makedirs(os.path.dirname(self.source), exist_ok=True) + os.umask(old_umask) # backup the file if "mudpy.limit" in self.universe.contents: