changes the file user/group permissions

@param $mode int

@return bool
550341
public function change_permission($mode)
    {

        if (empty($mode) || !is_int($mode)) return false;

        if (chmod($this->path . $this->filename, $mode)) {
            return $this->open($this->path . $this->filename);
        }

        return false;
    }
397289
protected function change_subscription($folders, $mode)
    {
        $updated = 0;
        $folders = (array) $folders;

        if (!empty($folders)) {
            if (!$this->check_connection()) {
                return false;
            }

            foreach ($folders as $folder) {
                $updated += (int) $this->conn->{$mode}($folder);
            }
        }

        // clear cached folders list(s)
        if ($updated) {
            $this->clear_cache('mailboxes', true);
        }

        return $updated == count($folders);
    }
86648
protected function changePermission($path, $octal = 0755)
    {
        $status = false;

        if(!is_writable($path))
            chmod($path, $octal);

        if(!is_readable($path))
            chmod($path, $octal);

        if(is_readable($path) && is_writable($path))
            $status = true;

        return $status;

    }
1074265
public function setPermissions($folder)
    {
        // Get path to folder
        $folder = $this->releasesManager->getCurrentReleasePath($folder);
        $this->explainer->line('Setting permissions for '.$folder);

        // Get permissions options
        $callback = $this->config->getContextually('remote.permissions.callback');
        $commands = (array) $callback($folder, $this);

        // Cancel if setting of permissions is not configured
        if (empty($commands)) {
            return true;
        }

        return $this->modulable->runForCurrentRelease($commands);
    }
337805
public function permission($permission): bool
    {
        $perms = fileperms($this->getAbsoluteFilePath());

        switch ($permission) {
            case FilePermission::READ_OWNER:
                return (($perms & 0x0100) ? true : false);

            case FilePermission::WRITE_OWNER:
                return (($perms & 0x0080) ? true : false);

            case FilePermission::EXE_OWNER:
                return (($perms & 0x0040) ?
                    (($perms & 0x0800) ? null /* 's' */ : true) :
                    (($perms & 0x0800) ? null /* 'S' */ : false));

            case FilePermission::READ_USER:
                return $this->isReadable();

            case FilePermission::WRITE_USER:
                return $this->isWritable();

            case FilePermission::EXE_USER:
                return $this->isExecutable();

            case FilePermission::READ_GROUP:
                return (($perms & 0x0020) ? true : false);

            case FilePermission::WRITE_GROUP:
                return (($perms & 0x0010) ? true : false);

            case FilePermission::EXE_GROUP:
                return (($perms & 0x0008) ?
                    (($perms & 0x0400) ? null /* 's' */ : true) :
                    (($perms & 0x0400) ? null /* 'S' */ : false));

            case FilePermission::READ_OTHER:
                return (($perms & 0x0004) ? true : false);

            case FilePermission::WRITE_OTHER:
                return (($perms & 0x0002) ? true : false);

            case FilePermission::EXE_OTHER:
                return (($perms & 0x0001) ?
                    (($perms & 0x0200) ? null /* 't' */ : true) :
                    (($perms & 0x0200) ? null /* 'T' */ : false));
        }

        return true;
    }
811909
public function change_group(): void
    {
        if (!userHasPermission('admin:auth:accounts:changeUserGroup') && !userHasPermission('admin:auth:accounts:changeOwnUserGroup')) {
            show404();
        }

        // --------------------------------------------------------------------------

        $oInput     = Factory::service('Input');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $aUserIds   = explode(',', $oInput->get('users'));
        $aUsers     = $oUserModel->getByIds($aUserIds);

        if (empty($aUsers)) {
            show404();
        }

        $aRemovedUsers = [];
        foreach ($aUsers as &$oUser) {
            if (
                ($oUserModel->isSuperuser($oUser) && !$oUserModel->isSuperuser())
                || ($oUser->id === activeUser('id') && !userHasPermission('admin:auth:accounts:changeOwnUserGroup'))
                || ($oUser->id !== activeUser('id') && !userHasPermission('admin:auth:accounts:changeUserGroup'))
            ) {
                $aRemovedUsers[] = $oUser;
                $oUser           = null;
            }
        }

        $aUsers = array_filter($aUsers);
        $aUsers = array_values($aUsers);

        if (!empty($aRemovedUsers)) {
            $this->data['warning'] = 'You do not have permission to change the group of the following users: ' .
                implode(', ', array_map(function ($oUser) {
                    return '<br><strong>#' . $oUser->id . ' ' . $oUser->first_name . ' ' . $oUser->last_name . '</strong>';
                }, $aRemovedUsers));
        }

        if (empty($aUsers)) {
            $this->data['error'] = 'No users selected';
        }

        // --------------------------------------------------------------------------

        $oUserGroupModel = Factory::model('UserGroup', 'nails/module-auth');
        $aGroups         = $oUserGroupModel->getAll();

        if (!isSuperuser()) {
            foreach ($aGroups as &$oGroup) {
                if (!empty($oGroup->acl) && in_array('admin:superuser', $oGroup->acl)) {
                    $oGroup = null;
                }
            }
        }

        $aGroups     = array_filter($aGroups);
        $aGroups     = array_values($aGroups);
        $aUserGroups = [];
        foreach ($aGroups as $oGroup) {
            $aUserGroups[$oGroup->id] = $oGroup->label;
        }

        // --------------------------------------------------------------------------

        if ($oInput->post()) {
            if ($oUserGroupModel->changeUserGroup(arrayExtractProperty($aUsers, 'id'), (int) $oInput->post('group_id'))) {
                $oSession = Factory::service('Session', 'nails/module-auth');
                $oSession->setFlashData('success', 'User group was updated successfully.');
                redirect('admin/auth/accounts');
            } else {
                $this->data['error'] = 'Failed to update user group. ' . $oUserGroupModel->lastError();
            }
        }


        $this->data['aUsers']      = $aUsers;
        $this->data['aUserGroups'] = $aUserGroups;
        $this->data['page']->title = 'Change a user\'s group';

        // --------------------------------------------------------------------------

        //  Load views
        Helper::loadView('changeGroup');
    }
956676
public function mkdir($mode = null)
    {
        if ($this->isAbsolute()) {
            if (is_null($mode)) {
                $mode = $this->defaul_permission;
            }

            if (mkdir($this->getPathname())) {
                $this->chmod($mode);
                return true;
            }
            return false;
        } else {
            throw new FileException('Given file path is not a absolute path.');
        }
    }
66137
protected function setAdminModeCheckout($mode)
    {
        $this->admin = null;

        if ($this->access('order_add')) {

            if ($mode === 'add') {
                $this->admin = 'add';
            }

            if ($mode === 'clone' && $this->access('order_edit')) {
                $this->admin = 'clone';
            }
        }
    }
664710
protected function changeMode($path, $mode)
    {
        $oldPermission = substr(sprintf('%o', fileperms($path)), -4);
        $newPermission = sprintf('%04o', $mode);
        if ($oldPermission !== $newPermission) {
            if(!@chmod($path, $mode)) {
                throw new CException (sprintf("Unable to change mode for %s, permission denied", $path));
            }
            echo sprintf("Changing mode for %s (%s => %s)... ", $path, $oldPermission, $newPermission);
            echo "done\n";
        }
    }
417023
private function chmod(string $path, int $mode): bool
    {
        if (!@chmod($path, $mode)) {
            $message = 'Could not change file mode.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return true;
    }
243034
public function setApplicationPermissions()
    {
        $files = (array) $this->config->getContextually('remote.permissions.files');
        foreach ($files as &$file) {
            $this->modulable->setPermissions($file);
        }

        return true;
    }
693248
public function switchAndSave( $mode ) {
		$this->originalMode = $this->mode;
		$this->mode = $mode;
		$this->handler = $this->dispatchTable[$mode];
		return $this->handler;
	}
610761
public function switchModeAction($mode)
    {
        //the session
        $session = $this->get('session');

        //memorize that we are in edit mode
        $session->set('victoire.edit_mode', $mode);

        return new JsonResponse(
            ['response' => true]
        );
    }
1368105
public static function setPermissions(string $path, int $mode = null)
    {
        $is_dir = is_dir($path);

        $current_uid = posix_getuid();
        $owner = @fileowner($path);
        if ($current_uid !== $owner)
            return;

        if (self::$file_group)
        {
            $current_gid = filegroup($path);
            $grpinfo = posix_getgrnam(self::$file_group);
            $wanted_gid = $grpinfo['gid'];
            if ($wanted_gid !== $current_gid)
            {
                try
                {
                    !@chgrp($path, self::$file_group);
                    clearstatcache(true, $path);
                }
                // @codeCoverageIgnoreStart
                // Impossible to test - this would require a RO file system
                catch (Throwable $e)
                {
                    throw new IOException(
                        "Could not set group on " . $path . " to " . self::$file_group
                    );
                }
                // @codeCoverageIgnoreEnd
            }
        }
        
        if ($mode === null)
            $mode = $is_dir ? self::$dir_mode : self::$file_mode;

        if (!empty($mode))
        {
            $perms = self::getPermissions($path);
            $current_mode = $perms['mode'];
            
            if ($mode !== $current_mode)
            {
                try
                {
                    @chmod($path, $mode);
                    clearstatcache(true, $path);
                }
                // @codeCoverageIgnoreStart
                // Impossible to test - this would require a RO file system
                catch (Throwable $e)
                {
                    throw new IOException(
                        "Could not set mode on " . $path . " to " . $mode
                    );
                }
                // @codeCoverageIgnoreEnd
            }
        }
    }
1296999
public static function chmod($path, $mode = NULL)
    {
        if (!isset($mode)) {
            if (is_file($path)) {
                $mode = Constants::FILESYSTEM_FILE_PERMISSIONS_DEFAULT;
            } elseif (is_dir($path)) {
                $mode = Constants::FILESYSTEM_DIR_PERMISSIONS_DEFAULT;
            } else {
                return false;
            }
        }
        $umask = umask();
        $res = chmod($path, $mode);
        umask($umask);

        return $res;
    }
472719
public function setMode($mode = 'and')
    {
        $mode = in_array($mode, ['and', 'or']) ? $mode : 'and';

        $this->mode = $mode;

        return $this;
    }
1096538
public function setMode(string $mode): WebAclRule {
        self::checkMode($mode);
        $this->mode = (int) $mode;
        return $this;
    }