Mercurial > hg
diff hgext/purge.py @ 8043:b777dd8f7836
purge: remove read-only files under Windows (issue583)
Initial version by Benoit Boissinot <bboissin@gmail.com>
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Fri, 10 Apr 2009 21:20:28 +0200 |
parents | e2c55c4a25e2 |
children | c1e2b7407dc3 |
line wrap: on
line diff
--- 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)):