Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Remove the immutable attribute of the given path.
Remove the immutable attribute of the file or folder located on the given
path. Also remove the immutable attribute of any file and folder below the
given one, recursively.
Args:
path (str): Path to the file or folder to remove the immutable
attribute for, recursively.
"""
# Some files have ACLs, let's remove them recursively
if (platform.system() == constants.PLATFORM_DARWIN) and os.path.isfile(
"/usr/bin/chflags"
):
subprocess.call(["/usr/bin/chflags", "-R", "nouchg", path])
elif platform.system() == constants.PLATFORM_LINUX and os.path.isfile(
"/usr/bin/chattr"
):
subprocess.call(["/usr/bin/chattr", "-R", "-i", path])
'/def' stays '/def'
Returns:
(bool): True if given file can be synced
"""
can_be_synced = True
# If the given path is relative, prepend home
fullpath = os.path.join(os.environ["HOME"], path)
# Compute the ~/Library path on OS X
# End it with a slash because we are looking for this specific folder and
# not any file/folder named LibrarySomething
library_path = os.path.join(os.environ["HOME"], "Library/")
if platform.system() == constants.PLATFORM_LINUX:
if fullpath.startswith(library_path):
can_be_synced = False
return can_be_synced
def remove_acl(path):
"""
Remove the ACL of the file or folder located on the given path.
Also remove the ACL of any file and folder below the given one,
recursively.
Args:
path (str): Path to the file or folder to remove the ACL for,
recursively.
"""
# Some files have ACLs, let's remove them recursively
if platform.system() == constants.PLATFORM_DARWIN and os.path.isfile("/bin/chmod"):
subprocess.call(["/bin/chmod", "-R", "-N", path])
elif (platform.system() == constants.PLATFORM_LINUX) and os.path.isfile(
"/bin/setfacl"
):
subprocess.call(["/bin/setfacl", "-R", "-b", path])
def remove_immutable_attribute(path):
"""
Remove the immutable attribute of the given path.
Remove the immutable attribute of the file or folder located on the given
path. Also remove the immutable attribute of any file and folder below the
given one, recursively.
Args:
path (str): Path to the file or folder to remove the immutable
attribute for, recursively.
"""
# Some files have ACLs, let's remove them recursively
if (platform.system() == constants.PLATFORM_DARWIN) and os.path.isfile(
"/usr/bin/chflags"
):
subprocess.call(["/usr/bin/chflags", "-R", "nouchg", path])
elif platform.system() == constants.PLATFORM_LINUX and os.path.isfile(
"/usr/bin/chattr"
):
subprocess.call(["/usr/bin/chattr", "-R", "-i", path])