##// 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 301 fp.close()
302 302
303 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 312 try:
306 313 if self.eol and self.eol != '\n':
307 314 for l in lines:
@@ -310,6 +317,8 b' class patchfile(object):'
310 317 fp.write(l)
311 318 else:
312 319 fp.writelines(lines)
320 if islink:
321 self.opener.symlink(fp.getvalue(), fname)
313 322 finally:
314 323 fp.close()
315 324
@@ -5,8 +5,23 b' now at: base.patch'
5 5 applying symlink.patch
6 6 now at: symlink.patch
7 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 21 % test symlink removal
9 now at: symlink.patch
22 now at: replacelinkwithfile
10 23 applying removesl.patch
11 24 now at: removesl.patch
12 25 C b
26 C c
27 C s
General Comments 0
You need to be logged in to leave comments. Login now