This is an archive of the discontinued LLVM Phabricator instance.

os.remove shouldn't fail, if file doesn't exist
ClosedPublic

Authored by ismailp on Nov 21 2014, 1:45 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

ismailp updated this revision to Diff 16507.Nov 21 2014, 1:45 PM
ismailp retitled this revision from to os.remove shouldn't fail, if file doesn't exist.
ismailp updated this object.
ismailp edited the test plan for this revision. (Show Details)
ismailp added a reviewer: emaste.
ismailp added a subscriber: Unknown Object (MLST).
ismailp edited subscribers, added: Unknown Object (MLST); removed: Unknown Object (MLST).Nov 21 2014, 1:46 PM

Moved to the correct list.

emaste added inline comments.Nov 21 2014, 1:59 PM
scripts/Python/buildSwigPython.py
686–687 ↗(On Diff #16507)

Do we not have the same issue here?

ismailp added inline comments.Nov 21 2014, 2:14 PM
scripts/Python/buildSwigPython.py
686–687 ↗(On Diff #16507)

Presumably, yes. I wasn't trying with LLDB_DISABLE_PYTHON, but with CMake generated Xcode project on Darwin, and region below failed. I didn't examine all instances of os.remove, I guess I should have.

How about:

def removeignoreenoent(filename):
  try:
    os.remove(filename)
  except OSError as e:
    import errno
    if e.errno != errno.ENOENT:
      raise
    pass

and call this function instead of os.remove. We might use a better/shorter name; any suggestions?

ismailp updated this revision to Diff 16515.Nov 21 2014, 3:52 PM

Added a new function called removeignoreenoent.

zturner added inline comments.
scripts/Python/buildSwigPython.py
435 ↗(On Diff #16515)

Please add underscores between the words, to be consistent with the naming convention used elsewhere in this function.

ismailp updated this revision to Diff 16518.Nov 21 2014, 4:37 PM

Use underscores in function name to match with the existing style.

emaste edited edge metadata.Nov 21 2014, 5:04 PM

Looks fine with a couple of minor comments.

scripts/Python/buildSwigPython.py
431–433 ↗(On Diff #16518)

This comment seems overly verbose -- it's clear from reading the function that this is what happens. What about something succinct like "Remove a file, ignoring error if it does not exist."

604 ↗(On Diff #16518)

random whitespace change

ismailp updated this revision to Diff 16531.Nov 22 2014, 12:57 PM
ismailp edited edge metadata.

Added a succint comment, and removed whitespace change.

emaste accepted this revision.Jan 28 2015, 7:48 PM
emaste edited edge metadata.

lgtm

This revision is now accepted and ready to land.Jan 28 2015, 7:48 PM
ki.stfu accepted this revision.Jan 28 2015, 9:55 PM
ki.stfu added a reviewer: ki.stfu.
ki.stfu added a subscriber: ki.stfu.

lgtm

ismailp,

it was committed?

Friendly ping

ki.stfu removed a subscriber: ki.stfu.
This revision was automatically updated to reflect the committed changes.

Thanks, landed in r229334.