# HG changeset patch # User Patrick Mezard # Date 2009-04-10 22:13:18 # Node ID c1e2b7407dc3bcbed421989d9f1ba94089f7f0df # Parent b777dd8f7836d55568e088298c8ff10033b15ff2 purge: fix b777dd8f7836 (remove read-only files) - use try/except to avoid unnecessary work - edit only mode bits diff --git a/hgext/purge.py b/hgext/purge.py --- a/hgext/purge.py +++ b/hgext/purge.py @@ -73,11 +73,15 @@ def purge(ui, repo, *dirs, **opts): ui.write('%s%s' % (name, eol)) def removefile(path): - # read-only files cannot be unlinked under Windows - s = os.stat(path) - if (s.st_dev & stat.S_IWRITE) == 0: - os.chmod(path, s.st_mode | stat.S_IWRITE) - os.remove(path) + try: + os.remove(path) + except OSError: + # read-only files cannot be unlinked under Windows + s = os.stat(path) + if (s.st_mode & stat.S_IWRITE) != 0: + raise + os.chmod(path, stat.S_IMODE(s.st_mode) | stat.S_IWRITE) + os.remove(path) directories = [] match = cmdutil.match(repo, dirs, opts) diff --git a/tests/test-purge b/tests/test-purge --- a/tests/test-purge +++ b/tests/test-purge @@ -38,7 +38,7 @@ touch untracked_file_readonly python <