##// END OF EJS Templates
patch: handle symlink updates/replacements (issue1785)
Patrick Mezard -
r9586:d08099e7 default
parent child Browse files
Show More
@@ -301,7 +301,14 b' class patchfile(object):'
301 fp.close()
301 fp.close()
302
302
303 def writelines(self, fname, lines):
303 def writelines(self, fname, lines):
304 fp = self.opener(fname, 'w')
304 # Ensure supplied data ends in fname, being a regular file or
305 # a symlink. updatedir() will -too magically- take care of
306 # setting it to the proper type afterwards.
307 islink = os.path.islink(fname)
308 if islink:
309 fp = cStringIO.StringIO()
310 else:
311 fp = self.opener(fname, 'w')
305 try:
312 try:
306 if self.eol and self.eol != '\n':
313 if self.eol and self.eol != '\n':
307 for l in lines:
314 for l in lines:
@@ -310,6 +317,8 b' class patchfile(object):'
310 fp.write(l)
317 fp.write(l)
311 else:
318 else:
312 fp.writelines(lines)
319 fp.writelines(lines)
320 if islink:
321 self.opener.symlink(fp.getvalue(), fname)
313 finally:
322 finally:
314 fp.close()
323 fp.close()
315
324
@@ -5,8 +5,23 b' now at: base.patch'
5 applying symlink.patch
5 applying symlink.patch
6 now at: symlink.patch
6 now at: symlink.patch
7 a -> b
7 a -> b
8 % test updating a symlink
9 a -> c
10 now at: symlink.patch
11 applying updatelink
12 patching file a
13 a
14 now at: updatelink
15 a -> c
16 % test replacing a symlink with a file
17 now at: addlink
18 applying replacelinkwithfile
19 now at: replacelinkwithfile
20 sss
8 % test symlink removal
21 % test symlink removal
9 now at: symlink.patch
22 now at: replacelinkwithfile
10 applying removesl.patch
23 applying removesl.patch
11 now at: removesl.patch
24 now at: removesl.patch
12 C b
25 C b
26 C c
27 C s
General Comments 0
You need to be logged in to leave comments. Login now