sapling/eden/scm/edenscm/mercurial/fscap.py
Xavier Deguillard 674e9c7900 fsinfo: return an enum instead of a String
Summary:
In a strongly typed langage, using strings should be avoided whenever possible
as they do not provide the safety guarantees that types provide.

I took the liberty of removing all the filesystems that are not relevant for
Mercurial for simplification reasons. If needs arise, we can always add a new
FsType to the enum.

Reviewed By: DurhamG

Differential Revision: D20517138

fbshipit-source-id: 0a38b53c6a87f05f4b2d664038e10c4293de96ae
2020-03-23 14:29:10 -07:00

49 lines
1.4 KiB
Python

# Portions Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2.
# Copyright Matt Mackall <mpm@selenic.com> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""capabilities of well-known filesystems"""
SYMLINK = "symlink"
HARDLINK = "hardlink"
EXECBIT = "execbit"
ALWAYSCASESENSITIVE = "alwayscasesensitive"
_ALL_CAPS = {SYMLINK: True, HARDLINK: True, EXECBIT: True, ALWAYSCASESENSITIVE: True}
_EDENFS_POSIX_CAPS = {
SYMLINK: True,
HARDLINK: False,
EXECBIT: True,
ALWAYSCASESENSITIVE: True,
}
_FS_CAP_TABLE = {
"APFS": {SYMLINK: True, HARDLINK: True, EXECBIT: True, ALWAYSCASESENSITIVE: False},
"Btrfs": _ALL_CAPS,
"EdenFS": _EDENFS_POSIX_CAPS,
"ext4": _ALL_CAPS,
"NTFS": {
SYMLINK: False,
HARDLINK: True,
EXECBIT: False,
ALWAYSCASESENSITIVE: False,
},
"HFS": {SYMLINK: True, HARDLINK: True, EXECBIT: True, ALWAYSCASESENSITIVE: False},
"XFS": _ALL_CAPS,
"tmpfs": _ALL_CAPS,
}
def getfscap(fstype, cap):
"""Test if a filesystem has specified capability.
Return True if it has, False if it doesn't, or None if unsure.
"""
return _FS_CAP_TABLE.get(fstype, {}).get(cap)