/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/osutils.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2019-06-04 00:08:59 UTC
  • mfrom: (7122.6.12 win-symlink-warning)
  • Revision ID: breezy.the.bot@gmail.com-20190604000859-2xwms4tkctrj83dm
Allow symbolic links to exist when checking out trees on Windows.

Merged from https://code.launchpad.net/~jelmer/brz/win-symlink-warning/+merge/363900

Show diffs side-by-side

added added

removed removed

Lines of Context:
1662
1662
    _terminal_size = _ioctl_terminal_size
1663
1663
 
1664
1664
 
1665
 
def supports_executable():
1666
 
    return sys.platform != "win32"
 
1665
def supports_executable(path):
 
1666
    """Return if filesystem at path supports executable bit.
 
1667
 
 
1668
    :param path: Path for which to check the file system
 
1669
    :return: boolean indicating whether executable bit can be stored/relied upon
 
1670
    """
 
1671
    if sys.platform == 'win32':
 
1672
        return False
 
1673
    try:
 
1674
        fs_type = get_fs_type(path)
 
1675
    except errors.DependencyNotPresent as e:
 
1676
        trace.mutter('Unable to get fs type for %r: %s', path, e)
 
1677
    else:
 
1678
        if fs_type in ('vfat', 'ntfs'):
 
1679
            # filesystems known to not support executable bit
 
1680
            return False
 
1681
    return True
 
1682
 
 
1683
 
 
1684
def supports_symlinks(path):
 
1685
    """Return if the filesystem at path supports the creation of symbolic links.
 
1686
 
 
1687
    """
 
1688
    if not has_symlinks():
 
1689
        return False
 
1690
    try:
 
1691
        fs_type = get_fs_type(path)
 
1692
    except errors.DependencyNotPresent as e:
 
1693
        trace.mutter('Unable to get fs type for %r: %s', path, e)
 
1694
    else:
 
1695
        if fs_type in ('vfat', 'ntfs'):
 
1696
            # filesystems known to not support symlinks
 
1697
            return False
 
1698
    return True
1667
1699
 
1668
1700
 
1669
1701
def supports_posix_readonly():
2602
2634
    return False
2603
2635
 
2604
2636
 
 
2637
def get_fs_type(path):
 
2638
    """Return the filesystem type for the partition a path is in.
 
2639
 
 
2640
    :param path: Path to search filesystem type for
 
2641
    :return: A FS type, as string. E.g. "ext2"
 
2642
    """
 
2643
    # TODO(jelmer): It would be nice to avoid an extra dependency here, but the only
 
2644
    # alternative is reading platform-specific files under /proc :(
 
2645
    try:
 
2646
        import psutil
 
2647
    except ImportError as e:
 
2648
        raise errors.DependencyNotPresent('psutil', e)
 
2649
 
 
2650
    if not PY3 and not isinstance(path, str):
 
2651
        path = path.encode(_fs_enc)
 
2652
 
 
2653
    for part in sorted(psutil.disk_partitions(), key=lambda x: len(x.mountpoint), reverse=True):
 
2654
        if is_inside(part.mountpoint, path):
 
2655
            return part.fstype
 
2656
    # Unable to parse the file? Since otherwise at least the entry for / should match..
 
2657
    return None
 
2658
 
 
2659
 
2605
2660
if PY3:
2606
2661
    perf_counter = time.perf_counter
2607
2662
else: