Skip to content

Commit

Permalink
os.remove shouldn't fail, if file doesn't exist
Browse files Browse the repository at this point in the history
Summary:
os.remove might throw an exception (of type OSError), if given file
doesn't exist. Catch the exception, and ignore it //iff// errno is
ENOENT. Rethrow the exception, if errno is not ENOENT.

Reviewers: emaste

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D6362

llvm-svn: 229334
  • Loading branch information
ipazarbasi committed Feb 15, 2015
1 parent b1607ab commit 323e3b6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lldb/scripts/Python/buildSwigPython.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,18 @@ def get_config_build_dir( vDictArgs, vstrFrameworkPythonDir ):

return (bOk, strConfigBldDir, strErrMsg);

"""
Removes given file, ignoring error if it doesn't exist.
"""
def remove_ignore_enoent(filename):
try:
os.remove( strSwigOutputFile );
except OSError as e:
import errno
if e.errno != errno.ENOENT:
raise
pass

#++---------------------------------------------------------------------------
# Details: Do a SWIG code rebuild. Any number returned by SWIG which is not
# zero is treated as an error. The generate dependencies flag decides
Expand Down Expand Up @@ -685,7 +697,7 @@ def main( vDictArgs ):
# iOS be sure to set LLDB_DISABLE_PYTHON to 1.
if (strEnvVarLLDBDisablePython != None) and \
(strEnvVarLLDBDisablePython == "1"):
os.remove( strSwigOutputFile );
remove_ignore_enoent( strSwigOutputFile )
open( strSwigOutputFile, 'w' ).close(); # Touch the file
if bDebug:
strMsg = strMsgLldbDisablePython;
Expand All @@ -698,7 +710,7 @@ def main( vDictArgs ):
None );
if (strEnvVarGccPreprocessDefs != None) or \
(strEnvVarLLDBDisablePython != None):
os.remove( strSwigOutputFile );
remove_ignore_enoent( strSwigOutputFile )
open( strSwigOutputFile, 'w' ).close(); # Touch the file
if bDebug:
strMsg = strMsgLldbDisableGccEnv;
Expand Down

0 comments on commit 323e3b6

Please sign in to comment.