# HG changeset patch # User Patrick Mezard # Date 1239391228 -7200 # Node ID b777dd8f7836d55568e088298c8ff10033b15ff2 # Parent fd35e9d7287922d94746fd163fdc453e7c824439 purge: remove read-only files under Windows (issue583) Initial version by Benoit Boissinot diff -r fd35e9d72879 -r b777dd8f7836 hgext/purge.py --- a/hgext/purge.py Fri Apr 10 13:06:02 2009 +0200 +++ b/hgext/purge.py Fri Apr 10 21:20:28 2009 +0200 @@ -29,7 +29,7 @@ from mercurial import util, commands, cmdutil from mercurial.i18n import _ -import os +import os, stat def purge(ui, repo, *dirs, **opts): '''removes files not tracked by Mercurial @@ -72,6 +72,13 @@ else: 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) + directories = [] match = cmdutil.match(repo, dirs, opts) match.dir = directories.append @@ -79,7 +86,7 @@ for f in util.sort(status[4] + status[5]): ui.note(_('Removing file %s\n') % f) - remove(os.remove, f) + remove(removefile, f) for f in util.sort(directories)[::-1]: if match(f) and not os.listdir(repo.wjoin(f)): diff -r fd35e9d72879 -r b777dd8f7836 tests/test-purge --- a/tests/test-purge Fri Apr 10 13:06:02 2009 +0200 +++ b/tests/test-purge Fri Apr 10 21:20:28 2009 +0200 @@ -34,6 +34,12 @@ echo % delete an untracked file touch untracked_file +touch untracked_file_readonly +python <