Set permissions to writable directories if in non-production environment

@return $this
331492
private function setPermissions()
    {
        if (!App::environment('production') || $this->option('force')) {
            $this->comment("Setting write permissions");
            foreach ($this->writableDirectories as $path) {
                $this->process->setCommandLine('chmod -R 0777 ' . base_path($path));
                $this->process->setTimeout(null);
                $this->process->run();

                if (!$this->process->isSuccessful()) {
                    $this->error("Could not set write permissions to " . $path);
                    break;
                }
            }

            $this->comment("Permissions set successfully");

            return $this;
        }else{
            $this->error("Write permissions can not be set in production environment. use --force option if you are really sure you want to proceed!");
        }
    }
854623
public function getPermissionsInherited()
    {
        $rights = [];
        $permissions = $this->permissions;

        // ntfs permissions
        // determine if ntfs is enabled
        // then more permissive wins
        $tmp = [];
        $letNtfs = function ($alias, $slug) use (&$tmp) {
            if ( config('acl.most_permissive_wins', false) ) {
                $ntfs[$alias] = array_diff($slug, [false]);
                if ( sizeof($ntfs) > 0 ) {
                    $tmp = array_replace_recursive($tmp, $ntfs);
                }
            }
        };

        foreach ($permissions as $row) {

            // permissions without inherit ids
            if ( is_null($row->inherit_id) || ! $row->inherit_id ) {

                // ntfs determination
                $letNtfs($row->name, $row->slug);

                // merge permissions
                $rights = array_replace_recursive($rights, [$row->name => $row->slug], $tmp);
                continue;
            }

            // process inherit_id recursively
            $inherited = $this->getRecursiveInherit($row->inherit_id, $row->slug);
            $merge = $permissions->where('name', $row->name);
            $merge = method_exists($merge, 'pluck') ? $merge->pluck('slug', 'name') : $merge->lists('slug', 'name');

                // fix for l5.1 and backward compatibility.
            // lists() method should return as an array.
            $merge = $this->collectionAsArray($merge);

            // replace and merge permissions
            $rights = array_replace_recursive($rights, $inherited, $merge);

            // make sure we don't unset if
            // inherited & slave permission
            // have same names
            if ( key($inherited) != $row->name )
                unset($rights[$row->name]);

        }

        return $rights;
    }
753842
public function perms($value = false)
    {
        if ($value === false) {
            return substr(sprintf('%o', $this->adapter->fileperms($this->path)), -4);
        }

        if (! $this->adapter->chmod($this->path, $value)) {
            throw new FilesystemException("Unable to apply permissions to '{$this->path}'");
        }

        $this->clearStat();

        return $this;
    }
707848
public function setPermissionsAttribute($permissions)
    {
        if (! ($permissions instanceof ChannelPermission)) {
            return;
        }

        list($allow, $deny) = $permissions->bitwise;
        $this->allow        = $allow;
        $this->deny         = $deny;

        $this->attributes['permissions'] = $permissions;
    }
1349332
protected function _set()
	{
		$payload = $this->prep_contents();
		$id_path = $this->identifier_to_path($this->identifier);

		// create directory if necessary
		$subdirs = explode(DS, $id_path);
		if (count($subdirs) > 1)
		{
			array_pop($subdirs);

			// check if specified subdir exists
			if ( ! @is_dir(static::$path.implode(DS, $subdirs)))
			{
				// recursively create the directory. we can't use mkdir permissions or recursive
				// due to the fact that mkdir is restricted by the current users umask
				$basepath = rtrim(static::$path,DS);
				$chmod = \Config::get('file.chmod.folders', 0775);
				foreach ($subdirs as $dir)
				{
					$basepath .= DS.$dir;
					if ( ! is_dir($basepath))
					{
						try
						{
							if ( ! mkdir($basepath))
							{
								return false;
							}
							chmod($basepath, $chmod);
						}
						catch (\PHPErrorException $e)
						{
							return false;
						}
					}
				}
			}
		}

		// write the cache
		$file = static::$path.$id_path.'.cache';

		$handle = fopen($file, 'c');

		if ( ! $handle)
		{
			return false;
		}

		// wait for a lock
		while ( ! flock($handle, LOCK_EX));

		// truncate the file
		ftruncate($handle, 0);

		// write the session data
		fwrite($handle, $payload);

		//release the lock
		flock($handle, LOCK_UN);

		// close the file
		fclose($handle);

		// set the correct rights on the file
		chmod($file, \Config::get('file.chmod.files', 0666));

		return true;
	}
666208
public function setPermissionsAttribute($permissions)
    {
        $module = lcfirst($this->attributes['name']);

        $roles = array();

        //prefix the permission with the module name ex: user.create
        foreach ($permissions as $key => $value)
        {
            $roles[] = $module . '.' . $value;
        }

        $this->attributes['permissions'] = ( ! empty($roles)) ? json_encode($roles) : '';
    }
94439
public function chmod(int $permissions): vfsStreamContent
    {
        $this->permissions           = $permissions;
        $this->lastAttributeModified = time();
        clearstatcache();
        return $this;
    }
852788
public function setDirectoryToParse($value)
    {
        $this->directoryToParse = trim(str_replace(DIRECTORY_SEPARATOR, '/', trim((string) $value)), '/');

        return $this;
    }
734744
public function mount() {
        $this->setSrcDisk($this->makeDisk($this->config['src_dir']));
        $this->setCropsDisk($this->makeDisk($this->config['crops_dir']));
        return $this;
    }
257673
public function setDirectory($path) {
        if (substr($path, -1) !== '/') {
            $path .= '/';
        }

        if (!file_exists($path)) {
            mkdir($path, 0777, true);

        } else if (!is_writable($path)) {
            chmod($path, 0777);
        }

        $this->_directory = $path;

        return $this;
    }
1052649
public function canWrite()
    {
        $ht = $this->getHTaccessFilename();
        $fs = $this->getFilesystem();

        return (bool) (@$fs->isFile($ht) ? @$fs->isWritable($ht) : @$fs->isWritable(@dirname($ht)));
    }
834657
public function create($permissions = 0755)
    {
        Filesystem::checkNotExists($this->path);
        Filesystem::checkWritable(dirname($this->path));
        mkdir($this->path, $permissions, true);
    }
682984
public function providePermissions()
    {
        $permissions = [];
        foreach (MenuSet::get() as $menuset) {
            $key = $menuset->PermissionKey();
            $permissions[$key] = [
                'name' => _t(
                    __CLASS__ . '.EDITMENUSET',
                    "Manage links with in '{name}'",
                    [
                        'name' => $menuset->obj('Title')
                    ]
                ),
                'category' => _t(__CLASS__ . '.MENUSETS', 'Menu sets')
            ];
        }
        return $permissions;
    }
1219392
static protected function is_log_dir_writable()
  {
    if (!is_writable(self::$log_dir))
      if (self::$to_stderr)
        error_log("Could't open " . self::$log_dir . " for writing. Does " . self::$log_dir . " exist? Permissions?");
  }
454837
public function dir()
    {
        $this->_name = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid($this->_prefix);
        if (!mkdir($this->_name)) {
            throw new \Exception('Cannot create temporary directory');
        }
        return $this;
    }
50072
public function detachPermission(...$permissions)
    {
        $this->eachPermission($permissions, function($permission) {
            if ($this->hasDirectPermission($permission)) {
                $this->permissions()->detach($permission->id);
            }
        });

        return $this;
    }
827224
protected function createDirectory()
        {
            $dir = $this->getDirectory();

            if (!$this->files->isDirectory($dir)) {
                $this->files->makeDirectory($dir, 0755, true);
            }

            return $this;
        }