1455 def checknlink(testfile): |
1455 def checknlink(testfile): |
1456 '''check whether hardlink count reporting works properly''' |
1456 '''check whether hardlink count reporting works properly''' |
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, f2, fd = None, None, None |
1460 f1, f2, fp = None, None, None |
1461 try: |
1461 try: |
1462 fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile), |
1462 fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile), |
1463 suffix='1~', dir=os.path.dirname(testfile)) |
1463 suffix='1~', dir=os.path.dirname(testfile)) |
1464 os.close(fd) |
1464 os.close(fd) |
1465 fd = None |
|
1466 f2 = '%s2~' % f1[:-2] |
1465 f2 = '%s2~' % f1[:-2] |
1467 |
1466 |
1468 oslink(f1, f2) |
1467 oslink(f1, f2) |
1469 # nlinks() may behave differently for files on Windows shares if |
1468 # nlinks() may behave differently for files on Windows shares if |
1470 # the file is open. |
1469 # the file is open. |
1471 fd = posixfile(f2) |
1470 fp = posixfile(f2) |
1472 return nlinks(f2) > 1 |
1471 return nlinks(f2) > 1 |
1473 except OSError: |
1472 except OSError: |
1474 return False |
1473 return False |
1475 finally: |
1474 finally: |
1476 if fd is not None: |
1475 if fp is not None: |
1477 fd.close() |
1476 fp.close() |
1478 for f in (f1, f2): |
1477 for f in (f1, f2): |
1479 try: |
1478 try: |
1480 if f is not None: |
1479 if f is not None: |
1481 os.unlink(f) |
1480 os.unlink(f) |
1482 except OSError: |
1481 except OSError: |