Change permissions recursively

@param string $path Path to chmod
@param numeric $dirMode Mode to set for folders
@param numeric $fileMode Mode to set for files
@return boolean
766834
protected static function chmodPathRecursive($path, $dirMode, $fileMode)
    {
        $result = false;

        $dirMode = self::valueToOct($dirMode);
        $fileMode = self::valueToOct($fileMode);

        $finder = new Finder();
        // Folders first
        foreach ($finder->directories()->in($path) as $item) {
            $result = chmod($item->getRealPath(), $dirMode);
        }
        // Files next
        foreach ($finder->files()->in($path) as $item) {
            $result = chmod($item->getRealPath(), $fileMode);
        }

        return $result;
    }
247491
protected function setPath($path, $permission)
    {
        if (true !== $this->files->exists($path)) {
            $this->files->mkdir($path, $permission, true);
        }
        $this->path = $path;
    }
620131
public function chmod($path, $mod = 0777)
    {
        if ($this->adapter instanceof Local) {
            return chmod($path, $mod);
        }

        return false;
    }
438644
def _set_mode(self):
        
        if self.mode is not None:
            logger.debug("changing permission bits of %s to %s", self.path, oct(self.mode))
            os.chmod(self.path, self.mode)
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;
    }
726650
public function chmod($path, $value)
    {
        $node = $this->at($path);
        if (null === $node || !is_numeric($value)) {
            return false;
        }
        $node->perms = $value;
        return 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
            }
        }
    }
395856
public static function chmod($path, $perm)
    {

        // don't do anything under Windows
        if (FileSystem::getOsIdentifier() === self::OS_IDENTIFIER_WIN) {
            return;
        }

        // change the mode
        if (chmod($path, $perm) === false) {
            throw new \Exception(sprintf('Can\'t change mode for directory %s to %s', $path, $perm));
        }
    }
1290290
function(callback) {
            // Optional permission modification
            if (disablePerms) {
              callback();
              return;
            }
            
            grunt.verbose.writeln('changing file perms...');

            // 511 = 0777 octal
            ftpout.raw.site('chmod', (file.mode & 511).toString(8), file.dest, function(err) {
              // Windows and some hosts don't implement the CHMOD site extension
              if (err && err.code !== 502 && err.code !== 504) {
                done(err);
                return;
              }

              grunt.verbose.writeln('done changing perms');
              callback();
            });
          }
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.');
        }
    }
688638
public function makeDirectory(string $path, int $mode = 0777, bool $isRecursive = false) : bool
    {
        $result = mkdir($path, $mode, $isRecursive);
        // The directory might not get the correct mode due to umask, so we have to chmod it
        chmod($path, $mode);

        return $result;
    }
223192
public function chmod($fileMode)
    {
        if ($this->exists()) {
            // file mode must be from type octal. through converting octal to decimal and the other way around
            // we going sure that the given value is a octal. Any non octal number will be detected.
            if (decoct(octdec($fileMode)) != $fileMode) {
                throw new FileException('Chmod failed, because given permission is not from type octal.');
            }

            // convert a given octal string to a octal integer
            if (is_string($fileMode)) {
                $fileMode = intval($fileMode, 8);
            }

            switch ($fileMode) {
                case 0600: // file owner read and write;
                case 0640: // file owner read and write; owner group read
                case 0660: // file owner read and write; owner group read and write
                case 0604: // file owner read and write; everbody read
                case 0606: // file owner read and write; everbody read and write
                case 0664: // file owner read and write; owner group read and write; everbody read
                case 0666: // file owner read and write; owner group read and write; everbody read and write
                case 0700: // file owner read, execute and write;
                case 0740: // file owner read, execute and write; owner group read
                case 0760: // file owner read, execute and write; owner group read and write
                case 0770: // file owner read, execute and write; owner group read, execute and write
                case 0704: // file owner read, execute and write; everbody read
                case 0706: // file owner read, execute and write; everbody read and write
                case 0707: // file owner read, execute and write; everbody read, execute and write
                case 0744: // file owner read, execute and write; owner group read; everbody read
                case 0746: // file owner read, execute and write; owner group read; everbody read and write
                case 0747: // file owner read, execute and write; owner group read; everbody read, execute and write
                case 0754: // file owner read, execute and write; owner group read and execute; everbody read
                case 0755: // file owner read, execute and write; owner group read and execute; everbody read and execute
                case 0756: // file owner read, execute and write; owner group read and execute; everbody read and write
                case 0757: // file owner read, execute and write; owner group read and execute; everbody read, execute and write
                case 0764: // file owner read, execute and write; owner group read and write; everbody read
                case 0766: // file owner read, execute and write; owner group read and write; everbody read and write
                case 0767: // file owner read, execute and write; owner group read and write; everbody read, execute and write
                case 0774: // file owner read, execute and write; owner group read, execute and write; everbody read
                case 0775: // file owner read, execute and write; owner group read, execute and write; everbody read, execute and write
                case 0776: // file owner read, execute and write; owner group read, execute and write; everbody read and write
                case 0777: // file owner read, execute and write; owner group read, execute and write; everbody read, execute and write
                    break;
                default:
                    $fileMode = 0777;
            }

            return chmod($this->getPathname(), $fileMode);
        }
        return false;
    }
362236
public function mkdir($path, $permissions = null)
	{
		if ( ! $this->_is_conn())
		{
			return false;
		}

		$result = ftp_mkdir($this->_conn_id, $path);

		if ($result === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpFileAccessException('Unable to create directory');
			}
			return false;
		}

		// Set file permissions if needed
		if ($permissions !== null)
		{
			$this->chmod($path, (int) $permissions);
		}

		return true;
	}
1222815
public function setPermissions($permissions)
	{
		if (is_string($permissions))
		{
			$permissions = '0'.ltrim($permissions, '0');
			$permissions = octdec($permissions);
		}

		return chmod($this->path, $permissions);
	}
20999
public function changeFolder(String $path) : Bool
    {
        if( ftp_chdir($this->connect, $path) )
        {
            return true;
        }
        else
        {
            throw new FolderChangeDirException(NULL, $path);
        }
    }
578848
private void changeDirectoryPermissions(String dir, String mode, 
                                              boolean isRecursive) {
    int ret = 0;
    try {
      ret = FileUtil.chmod(dir, mode, isRecursive);
    } catch (Exception e) {
      LOG.warn("Exception in changing permissions for directory " + dir + 
                  ". Exception: " + e.getMessage());
    }
    if (ret != 0) {
      LOG.warn("Could not change permissions for directory " + dir);
    }
  }
1134398
public function mkdir($path, $mode, $options)
    {
        $container = $this->getContainerFromContext($path);
        $path = $this->stripScheme($path);
        $recursive = (bool) ($options & STREAM_MKDIR_RECURSIVE);

        try {
            //need to check all parents for permissions
            $parentPath = $path;
            while ($parentPath = dirname($parentPath)) {
                try {
                    $parent = $container->nodeAt($parentPath);
                    $permissionHelper = $container->getPermissionHelper($parent);
                    if (!$permissionHelper->isWritable()) {
                        trigger_error(sprintf('mkdir: %s: Permission denied', dirname($path)), E_USER_WARNING);

                        return false;
                    }
                    if ($parent instanceof Root) {
                        break;
                    }
                } catch (NotFoundException $e) {
                    break; //will sort missing parent below
                }
            }
            $container->createDir($path, $recursive, $mode);
        } catch (FileExistsException $e) {
            trigger_error($e->getMessage(), E_USER_WARNING);

            return false;
        } catch (NotFoundException $e) {
            trigger_error(sprintf('mkdir: %s: No such file or directory', dirname($path)), E_USER_WARNING);

            return false;
        }

        return true;
    }