##// END OF EJS Templates
purge: remove read-only files under Windows (issue583)...
Patrick Mezard -
r8043:b777dd8f default
parent child Browse files
Show More
@@ -29,7 +29,7 b''
29 29
30 30 from mercurial import util, commands, cmdutil
31 31 from mercurial.i18n import _
32 import os
32 import os, stat
33 33
34 34 def purge(ui, repo, *dirs, **opts):
35 35 '''removes files not tracked by Mercurial
@@ -72,6 +72,13 b' def purge(ui, repo, *dirs, **opts):'
72 72 else:
73 73 ui.write('%s%s' % (name, eol))
74 74
75 def removefile(path):
76 # read-only files cannot be unlinked under Windows
77 s = os.stat(path)
78 if (s.st_dev & stat.S_IWRITE) == 0:
79 os.chmod(path, s.st_mode | stat.S_IWRITE)
80 os.remove(path)
81
75 82 directories = []
76 83 match = cmdutil.match(repo, dirs, opts)
77 84 match.dir = directories.append
@@ -79,7 +86,7 b' def purge(ui, repo, *dirs, **opts):'
79 86
80 87 for f in util.sort(status[4] + status[5]):
81 88 ui.note(_('Removing file %s\n') % f)
82 remove(os.remove, f)
89 remove(removefile, f)
83 90
84 91 for f in util.sort(directories)[::-1]:
85 92 if match(f) and not os.listdir(repo.wjoin(f)):
@@ -34,6 +34,12 b' ls'
34 34
35 35 echo % delete an untracked file
36 36 touch untracked_file
37 touch untracked_file_readonly
38 python <<EOF
39 import os, stat
40 f= 'untracked_file_readonly'
41 os.chmod(f, os.stat(f).st_mode & ~stat.S_IWRITE)
42 EOF
37 43 hg purge -p
38 44 hg purge -v
39 45 ls
@@ -15,7 +15,9 b' directory'
15 15 r1
16 16 % delete an untracked file
17 17 untracked_file
18 untracked_file_readonly
18 19 Removing file untracked_file
20 Removing file untracked_file_readonly
19 21 directory
20 22 r1
21 23 % delete an untracked file in a tracked directory
General Comments 0
You need to be logged in to leave comments. Login now