##// END OF EJS Templates
checknlink: use a random temp file name for checking...
Jun Wu -
r34081:1104718f default
parent child Browse files
Show More
@@ -1457,21 +1457,14 b' def checknlink(testfile):'
1457
1457
1458 # testfile may be open, so we need a separate file for checking to
1458 # testfile may be open, so we need a separate file for checking to
1459 # work around issue2543 (or testfile may get lost on Samba shares)
1459 # work around issue2543 (or testfile may get lost on Samba shares)
1460 f1 = testfile + ".hgtmp1"
1460 f1, f2, fd = None, None, None
1461 if os.path.lexists(f1):
1462 return False
1463 try:
1461 try:
1464 posixfile(f1, 'w').close()
1462 fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile),
1465 except IOError:
1463 suffix='1~', dir=os.path.dirname(testfile))
1466 try:
1464 os.close(fd)
1467 os.unlink(f1)
1465 fd = None
1468 except OSError:
1466 f2 = '%s2~' % f1[:-2]
1469 pass
1467
1470 return False
1471
1472 f2 = testfile + ".hgtmp2"
1473 fd = None
1474 try:
1475 oslink(f1, f2)
1468 oslink(f1, f2)
1476 # nlinks() may behave differently for files on Windows shares if
1469 # nlinks() may behave differently for files on Windows shares if
1477 # the file is open.
1470 # the file is open.
@@ -1484,7 +1477,8 b' def checknlink(testfile):'
1484 fd.close()
1477 fd.close()
1485 for f in (f1, f2):
1478 for f in (f1, f2):
1486 try:
1479 try:
1487 os.unlink(f)
1480 if f is not None:
1481 os.unlink(f)
1488 except OSError:
1482 except OSError:
1489 pass
1483 pass
1490
1484
General Comments 0
You need to be logged in to leave comments. Login now