Change group permission recursive

@param string $filename
@param int $fileOctal - ex. 0644
@param int $dirOctal - ex. 0755

@return bool
421191
protected function chgrpRecurse($path, $group) {

        if (!file_exists($path)) {
            return false;
        }

        if (!is_dir($path)) {
            return $this->chgrpReal($path, $group);
        }

        $result = $this->chgrpReal($path, $group);

        $allFiles = $this->getFileManager()->getFileList($path);
        foreach ($allFiles as $item) {
            $result &= $this->chgrpRecurse($path . Utils\Util::getSeparator() . $item, $group);
        }

        return (bool) $result;
    }
1257906
protected function changePermission(string $path, $mode = 0755, bool $recursively = false): void
    {
        $filesystem = $this->getContainer()['files'];

        $filesystem->chmod($path, $mode);

        if ($recursively === false) {
            return;
        }

        $lists = $filesystem->allFiles($path);

        $ignoredPath = function ($dir) {
            return (\substr($dir, -3) === '/..' || \substr($dir, -2) === '/.');
        };

        // this is to check if return value is just a single file,
        // avoiding infinite loop when we reach a file.
        if ($lists !== [$path]) {
            foreach ($lists as $dir) {
                // Not a file or folder, ignore it.
                if (! $ignoredPath($dir)) {
                    $this->changePermission($dir, $mode, true);
                }
            }
        }
    }
891124
function _chmod_recursive($mode, $path, &$i)
    {
        if (!$this->_read_put_responses($i)) {
            return false;
        }
        $i = 0;
        $entries = $this->_list($path, true, false);

        if ($entries === false) {
            return $this->chmod($mode, $path);
        }

        // normally $entries would have at least . and .. but it might not if the directories
        // permissions didn't allow reading
        if (empty($entries)) {
            return false;
        }

        foreach ($entries as $filename=>$props) {
            if ($filename == '.' || $filename == '..') {
                continue;
            }

            if (!isset($props['type'])) {
                return false;
            }

            $temp = $path . '/' . $filename;
            if ($props['type'] == NET_SFTP_TYPE_DIRECTORY) {
                if (!$this->_chmod_recursive($mode, $temp, $i)) {
                    return false;
                }
            } else {
                $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
                if (!$this->_send_sftp_packet(NET_SFTP_SETSTAT, pack('Na*a*', strlen($temp), $temp, $attr))) {
                    return false;
                }

                $i++;

                if ($i >= 50) {
                    if (!$this->_read_put_responses($i)) {
                        return false;
                    }
                    $i = 0;
                }
            }
        }

        $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
        if (!$this->_send_sftp_packet(NET_SFTP_SETSTAT, pack('Na*a*', strlen($path), $path, $attr))) {
            return false;
        }

        $i++;

        if ($i >= 50) {
            if (!$this->_read_put_responses($i)) {
                return false;
            }
            $i = 0;
        }

        return true;
    }
1116195
static function changeFilePermissions( $filepath )
    {
        if ( !file_exists( $filepath ) )
            return false;
        $ini = eZINI::instance( 'image.ini' );
        $perm = $ini->variable( "FileSettings", "ImagePermissions" );
        $success = false;
        $oldmask = umask( 0 );
        if ( !chmod( $filepath, octdec( $perm ) ) )
            eZDebug::writeError( "Chmod $perm $filepath failed", __METHOD__ );
        else
            $success = true;
        umask( $oldmask );
        return $success;
    }
601566
public static function touch($filename, $content = '')
    {
        self::mkdir(dirname($filename));
        file_put_contents($filename, $content);
    }
392193
protected function retreivePermission($permissions, $check_permissions, $level)
    {
        $sorted_permissions = explode(',', $check_permissions);
        ksort($sorted_permissions);
        
        foreach ($sorted_permissions as $item) {
            $item = trim($item);
            if (! array_key_exists($item, $permissions) && ! empty($item)) {
                $permissions[$item] = $level;
            }
        }
        
        return $permissions;
    }
250244
function chmod($mode, $filename, $recursive = false)
    {
        if (is_string($mode) && is_int($filename)) {
            $temp = $mode;
            $mode = $filename;
            $filename = $temp;
        }

        $attr = pack('N2', NET_SFTP_ATTR_PERMISSIONS, $mode & 07777);
        if (!$this->_setstat($filename, $attr, $recursive)) {
            return false;
        }
        if ($recursive) {
            return true;
        }

        $filename = $this->_realPath($filename);
        // rather than return what the permissions *should* be, we'll return what they actually are.  this will also
        // tell us if the file actually exists.
        // incidentally, SFTPv4+ adds an additional 32-bit integer field - flags - to the following:
        $packet = pack('Na*', strlen($filename), $filename);
        if (!$this->_send_sftp_packet(NET_SFTP_STAT, $packet)) {
            return false;
        }

        $response = $this->_get_sftp_packet();
        switch ($this->packet_type) {
            case NET_SFTP_ATTRS:
                $attrs = $this->_parseAttributes($response);
                return $attrs['permissions'];
            case NET_SFTP_STATUS:
                $this->_logError($response);
                return false;
        }

        user_error('Expected SSH_FXP_ATTRS or SSH_FXP_STATUS');
        return false;
    }
109283
function mget($filelist) {

        $result = true;

        foreach ($filelist as $remotepath => $localpath) {

            $localpath   = rtrim($localpath, "/");
            $remotepath  = rtrim($remotepath, "/");

            // attempt to create local path
            if ($this->is_dir($remotepath)) {
                $pathparts = explode("/", $localpath."/ "); // add one level, last level will be created as dir
            } else {
                $pathparts = explode("/", $localpath);
            }
            $checkpath = "";
            for ($i=1; $i<sizeof($pathparts)-1; $i++) {
                $checkpath .= "/" . $pathparts[$i];
                if (!is_dir($checkpath)) {

                    $result &= mkdir($checkpath);
                }
            }

            if ($result) {
                // recurse directories
                if ($this->is_dir($remotepath)) {
                    $list = $this->ls($remotepath);

                    $fl = array();
                    foreach($list as $e) {
                        $fullpath = urldecode($e['href']);
                        $filename = basename($fullpath);
                        if ($filename != '' and $fullpath != $remotepath . '/') {
                            $fl[$remotepath."/".$filename] = $localpath."/".$filename;
                        }
                    }
                    $result &= $this->mget($fl);
                } else {
                    $result &= ($this->get_file($remotepath, $localpath));
                }
            }
        }
        return $result;
    }
457339
public static function changeFilePermissions($filename, $mode = 0644)
    {

        // make the passed filename OS compliant
        $toBeChanged = Setup::prepareOsSpecificPath($filename);

        // change the mode, if we're not on Windows
        if (SetupKeys::OS_FAMILY_WINDOWS !== strtolower(php_uname('s'))) {
            chmod($toBeChanged, $mode);
        }
    }
143110
public function rename($filename)
    {
        if ($this->exists() && !@rename($this->filename, $filename)) {
            return false;
        }

        unset(static::$instances[$this->filename]);
        static::$instances[$filename] = $this;

        $this->filename = $filename;

        return true;
    }
981025
public function setApacheAcl($path, $permissions, $recursive = false)
    {
        return $this->send('set_apache_acl', $path, $permissions, $recursive);
    }
268044
public function open($dir = null, $recursive = false, $grouped = false)
    {

        try {

            if (empty($dir)) {
                throw new FileException("The given path is empty", Config::get('file_error'), Config::get('error_lvl_low'), __FILE__, __LINE__);
            }

            if (!is_dir($dir)) {
                throw new FileException("The given path is not a directory", Config::get('file_error'), Config::get('error_lvl_low'), __FILE__, __LINE__);
            }

            if (!is_readable($dir)) {
                throw new FileException("The given path is not readable", Config::get('file_error'), Config::get('error_lvl_low'), __FILE__, __LINE__);
            }

            $this->dir = (string)$dir;

            $this->dh = opendir($this->dir);

            $this->recursive = $recursive;

            $this->grouped = $grouped;

            while (($file = readdir($this->dh)) !== false) {
                if ($file == '.' || $file == '..' || in_array($file, $this->exclude_pattern)) continue;

                if (is_file("$this->dir/$file")) {
                    $f = new File();
                    $f->open(Tool::clean_up_path("$this->dir/$file"));
                    if ($grouped === true) {
                        $this->list['file']["$this->dir/$file"] = $f;
                    } else {
                        $this->list["$this->dir/$file"] = $f;
                    }
                    unset($f);
                }

                if (is_dir("$this->dir/$file")) {
                    $d = new Directory();
                    $d->open(Tool::clean_up_path("$this->dir/$file"), $this->recursive);

                    if ($grouped === true) {
                        $this->list['directory']["$this->dir/$file"] = $d;
                    } else {
                        $this->list["$this->dir/$file"] = $d;
                    }

                    $this->list['directory'] = $d;
                    unset($d);
                }
            }

        } catch (FileException $e) {
            throw $e;
        }

        return true;
    }
1264357
private function updatePermission(Permission $permission, $permissionData)
    {
        $permission->setContext($permissionData['context']);

        $permission->setPermissions(
            $this->get('sulu_security.mask_converter')
                ->convertPermissionsToNumber($permissionData['permissions'])
        );

        return true;
    }
242110
public void changePermissions(SftpFile file, int permissions)
			throws SftpStatusException, SshException {
		SftpFileAttributes attrs = new SftpFileAttributes(this,
				SftpFileAttributes.SSH_FILEXFER_TYPE_UNKNOWN);
		attrs.setPermissions(new UnsignedInteger32(permissions));
		setAttributes(file, attrs);
	}
628838
public static function createFolder(String $file, Int $permission = 0755, Bool $recursive = true) : Bool
    {
        return Filesystem::createFolder(Info::rpath($file), $permission, $recursive);
    }
1120042
private function chgrp(string $path, int $group): bool
    {
        if (!@chgrp($path, $group)) {
            $message = 'Could not change file group.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return true;
    }
39519
public function chmod( $path, $mode, $recursive = false )
    {
        return $this->SFTPObject->chmod($mode, $path, $recursive);
	}