Check if the file at the given path is safe to use as a state file.

    This checks that group and others have no permissions on the file and that the current user is
    the owner.
190674
def check_permission_safety(path):
    
    f_stats = os.stat(path)
    return (f_stats.st_mode & (stat.S_IRWXG | stat.S_IRWXO)) == 0 and f_stats.st_uid == os.getuid()
448606
private void checkAllowedNonFileState(StorageState curState, Object name)
      throws IOException {
    switch (curState) {
    case NON_EXISTENT:
    case NOT_FORMATTED:
    case NORMAL:
      break;
    default:
      throwIOException("ImageManager bad state: " + curState + " for: "
          + name.toString());
    }
  }
22312
def file_is_present(self, file_path):
        
        p = self.p(file_path)
        if not os.path.exists(p):
            return False
        if not os.path.isfile(p):
            raise IOError("%s is not a file" % file_path)
        return True
1079722
def check_path(file_path):
    '''
        
    '''
    directory = os.path.dirname(file_path)
    if directory != '':
        if not os.path.exists(directory):
            os.makedirs(directory, 0o775)
644215
def file_verified?(path, expected_digest, digest_type=:md5)
      return false unless file_exists?(path)
      raise "Unknown disgest type: #{digest_type}" unless can?("digest_#{digest_type}")
      digest = self.send("digest_#{digest_type}", path).first
      info "#{digest_type} (#{path}) = #{digest}"
      digest.to_s == expected_digest.to_s
    end
815323
private boolean isArchive(Path file) {
        String n = StringUtils.toLowerCase(file.getFileName().toString());
        return fsInfo.isFile(file)
                && (n.endsWith(".jar") || n.endsWith(".zip"));
    }
898061
private void checkACL(String path, int perm) throws KeeperException.NoAuthException {
        DataAndVersion node = _data.get(path);
        if (node == null) {
            return;
        }
        List<ACL> acl = node.getAcl();
        if (acl == null || acl.size() == 0) {
            return;
        }
        for (Id authId : _ids) {
            if (authId.getScheme().equals("super")) {
                return;
            }
        }
        for (ACL a : acl) {
            Id id = a.getId();
            if ((a.getPerms() & perm) != 0) {
                if (id.getScheme().equals("world") && id.getId().equals("anyone")) {
                    return;
                }
                for (Id authId : _ids) {
                    if (authId.getScheme().equals(id.getScheme()) && authId.getId().equals(id.getId())) {
                        return;
                    }
                }
            }
        }
        throw new KeeperException.NoAuthException();
    }
481908
def check(path=None, env='default'):
    
    # TODO: add files=<list of files> to check only a subset...
    # also useful for 'quilt build' to exclude certain files?
    # (if not, then require dry_run=True if files!=None/all)
    build("dry_run/dry_run", path=path, dry_run=True, env=env)
1095294
def ca_file=(path)
      ssl_context.ca_file = path
      ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER unless path.nil?
    end
817358
public static boolean isAbsoluteAndSchemeAuthorityNull(Path path) {
    return (path.isAbsolute() &&
        path.toUri().getScheme() == null && path.toUri().getAuthority() == null);
  }
750893
def is_role(path):
    
    seems_legit = False
    for folder in c.ANSIBLE_FOLDERS:
        if os.path.exists(os.path.join(path, folder)):
            seems_legit = True

    return seems_legit
19535
def check_permissions(self, filename):
        '''
        
        '''
        if salt.utils.platform.is_windows():
            return True

        # After we've ascertained we're not on windows
        groups = salt.utils.user.get_gid_list(self.opts['user'], include_default=False)
        fmode = os.stat(filename)

        if stat.S_IWOTH & fmode.st_mode:
            # don't allow others to write to the file
            return False

        if stat.S_IWGRP & fmode.st_mode:
            # if the group has write access only allow with permissive_pki_access
            if not self.opts.get('permissive_pki_access', False):
                return False
            elif os.getuid() == 0 and fmode.st_gid not in groups:
                # if salt is root it has to be in the group that has write access
                # this gives the group 'permission' to have write access
                return False

        return True
603087
public function check()
    {
        if ($this->path[0] == '/') {
            $filename = $this->path;
        } else {
            $filename = BASE_PATH . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $this->path);
        }

        if (file_exists($filename)) {
            $isWriteable = is_writeable($filename);
        } else {
            $isWriteable = is_writeable(dirname($filename));
        }

        if (!$isWriteable) {
            if (function_exists('posix_getgroups')) {
                $userID = posix_geteuid();
                $user = posix_getpwuid($userID);

                $currentOwnerID = fileowner(file_exists($filename) ? $filename : dirname($filename));
                $currentOwner = posix_getpwuid($currentOwnerID);

                $message = "User '$user[name]' needs to be able to write to this file:\n$filename\n\nThe file is "
                    . "currently owned by '$currentOwner[name]'.  ";

                if ($user['name'] == $currentOwner['name']) {
                    $message .= 'We recommend that you make the file writeable.';
                } else {
                    $groups = posix_getgroups();
                    $groupList = [];
                    foreach ($groups as $group) {
                        $groupInfo = posix_getgrgid($group);
                        if (in_array($currentOwner['name'], $groupInfo['members'])) {
                            $groupList[] = $groupInfo['name'];
                        }
                    }
                    if ($groupList) {
                        $message .= "	We recommend that you make the file group-writeable and change the group to "
                            . "one of these groups:\n - " . implode("\n - ", $groupList)
                            . "\n\nFor example:\nchmod g+w $filename\nchgrp " . $groupList[0] . " $filename";
                    } else {
                        $message .= "  There is no user-group that contains both the web-server user and the owner "
                            . "of this file.  Change the ownership of the file, create a new group, or temporarily "
                            . "make the file writeable by everyone during the install process.";
                    }
                }
            } else {
                $message = "The webserver user needs to be able to write to this file:\n$filename";
            }

            return [EnvironmentCheck::ERROR, $message];
        }

        return [EnvironmentCheck::OK, ''];
    }
388930
def check_input_file_or_directory(self, path):
        
        if (not gf.file_can_be_read(path)) and (not os.path.isdir(path)):
            self.print_error(u"Unable to read file or directory '%s'" % (path))
            self.print_error(u"Make sure the path is written/escaped correctly and that you have read permission on it")
            return False
        return True
897072
private void setRecursivePermission(Path path, OwnerAndPermission ownerAndPermission)
      throws IOException {
    List<FileStatus> files = FileListUtils.listPathsRecursively(this.fs, path, FileListUtils.NO_OP_PATH_FILTER);

    // Set permissions bottom up. Permissions are set to files first and then directories
    Collections.reverse(files);

    for (FileStatus file : files) {
      safeSetPathPermission(file.getPath(), addExecutePermissionsIfRequired(file, ownerAndPermission));
    }
  }
906701
def check_files(self, to_path=None):
        
        if to_path:
            target_path = os.path.normpath(os.path.realpath(to_path))
        else:
            target_path = os.getcwd()
        for filename in self.filenames():
            extract_path = os.path.join(target_path, filename)
            extract_path = os.path.normpath(os.path.realpath(extract_path))
            if not extract_path.startswith(target_path):
                raise UnsafeArchive(
                    "Archive member destination is outside the target"
                    " directory.  member: %s" % filename)
136101
function checkFileExistsSync(filepath){
  var flag = true;

  try {
    fs.accessSync(filepath, fs.F_OK);
  } catch(e){
    flag = false;
  }

  return flag;
}