Properly detect existence of a symlink.

Review Request #1437 — Created Dec. 5, 2014 and submitted

benjyw
pants
19e1c73...
pants-reviews
patricklaw
os.path.exists() returns False for broken symlinks.


PA
  1. Ship It!

  2. 
      
ZU
  1. 
      
  2. Sounds like you want both exists() and islink(). What if for some reason there is a real file there? islink() would return False in that case.

    Or what about just an unconditional 'os.unlink()'? The docs don't say that it will raise an exception if there is no file there.

    1. Patrick raised that, but I think I want it to fail if there's anything other than a symlink there because that would imply that some logic is seriously wrong.

      Un unconditional os.unlink() fails with "OSError: [Errno 2] No such file or directory".

      I suppose we could just catch and ignore.

    2. In fact, catch and ignore would solve the theoretical race condition that exists here.

    3. Well, one of the two race conditions. There's still a race between unlink() and symlink().

  3. 
      
BE
Review request changed

Status: Closed (submitted)

Change Summary:

Submitted as facaf5bbbb39fe2e3e4bef40cbb4be005f39cf11.
Loading...