コード例 #1
0
def set_read_only(path, read_only):
    """Sets or resets the write bit on a file or directory.

  Zaps out access to 'group' and 'others'.
  """
    mode = fs.lstat(path).st_mode
    # TODO(maruel): Stop removing GO bits.
    mode = (mode & 0500) if read_only else (mode | 0200)
    if hasattr(os, 'lchmod'):
        fs.lchmod(path, mode)  # pylint: disable=E1101
    else:
        if stat.S_ISLNK(mode):
            # Skip symlink without lchmod() support.
            logging.debug('Can\'t change %sw bit on symlink %s',
                          '-' if read_only else '+', path)
            return

        # TODO(maruel): Implement proper DACL modification on Windows.
        fs.chmod(path, mode)
コード例 #2
0
ファイル: file_path.py プロジェクト: mellowdistrict/luci-py
def set_read_only(path, read_only):
  """Sets or resets the write bit on a file or directory.

  Zaps out access to 'group' and 'others'.
  """
  mode = fs.lstat(path).st_mode
  # TODO(maruel): Stop removing GO bits.
  mode = (mode & 0500) if read_only else (mode | 0200)
  if hasattr(os, 'lchmod'):
    fs.lchmod(path, mode)  # pylint: disable=E1101
  else:
    if stat.S_ISLNK(mode):
      # Skip symlink without lchmod() support.
      logging.debug(
          'Can\'t change %sw bit on symlink %s',
          '-' if read_only else '+', path)
      return

    # TODO(maruel): Implement proper DACL modification on Windows.
    fs.chmod(path, mode)
コード例 #3
0
def set_read_only(path, read_only):
    """Sets or resets the write bit on a file or directory.

  Zaps out access to 'group' and 'others'.
  """
    mode = fs.lstat(path).st_mode
    # TODO(maruel): Stop removing GO bits.
    if read_only:
        mode &= stat.S_IRUSR | stat.S_IXUSR  # 0500
    else:
        mode |= stat.S_IRUSR | stat.S_IWUSR  # 0600
        if sys.platform != 'win32' and stat.S_ISDIR(mode):
            mode |= stat.S_IXUSR  # 0100
    if hasattr(os, 'lchmod'):
        fs.lchmod(path, mode)  # pylint: disable=E1101
    else:
        if stat.S_ISLNK(mode):
            # Skip symlink without lchmod() support.
            return

        # TODO(maruel): Implement proper DACL modification on Windows.
        fs.chmod(path, mode)