checkFilePermissions
Check the log directory / file and make sure
they're writable. If the log file doesn't exist
it's created here.

@return void
487676
protected function checkFilePermissions()
    {
        if (!is_dir($this->logDir)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot locate log directory: %s', $this->logDir)
            );
        }

        if ((!file_exists($this->logFile)) && (!touch($this->logFile))) {
            throw new \InvalidArgumentException(
                sprintf('Cannot create log file: %s', $this->logFile)
            );
        } elseif (!is_writable($this->logFile)) {
            throw new \InvalidArgumentException(
                sprintf('Cannot write to log file: %s', $this->logFile)
            );
        }
    }
492198
public function check(): bool
    {
        $path = \app()->storagePath();

        $this->description = Str::replace($this->description, \compact('path'));

        return $this->checkPathIsWritable($path);
    }
442151
def ensure_writable(self):
        """"""
        self.ensure_exists()
        if not self.context.is_writable(self.directory):
            if self.context.have_superuser_privileges:
                msg = "The directory %s isn't writable!"
                raise ValueError(msg % self)
            else:
                raise ValueError(compact("""
                    The directory {location} isn't writable, most likely due
                    to permissions. Consider using the --use-sudo option.
                """, location=self))
870746
function open()
    {
        if (!$this->_opened) {
            /* If the log file's directory doesn't exist, create it. */
            if (!is_dir(dirname($this->_filename))) {
                $this->_mkpath($this->_filename, $this->_dirmode);
            }

            /* Determine whether the log file needs to be created. */
            $creating = !file_exists($this->_filename);

            /* Obtain a handle to the log file. */
            $this->_fp = fopen($this->_filename, ($this->_append) ? 'a' : 'w');

            /* We consider the file "opened" if we have a valid file pointer. */
            $this->_opened = ($this->_fp !== false);

            /* Attempt to set the file's permissions if we just created it. */
            if ($creating && $this->_opened) {
                chmod($this->_filename, $this->_mode);
            }
        }

        return $this->_opened;
    }
986730
protected function checkEnvironment()
    {
        // Check chunk folder is writable.
        // If not, give feedback!
        $chunkFolder = $this->config->getChunkDir();
        if (is_writeable($chunkFolder) === false) {
            $chunkFolder = $this->fileService->filterFilePath($chunkFolder);
            $this->messages->addMessage('chunksNotWritable', array($chunkFolder));
            // We can work without chunks, but this will require much more memory!
            $this->chunks->setUseChunks(false);
        }

        // Check if the log folder is writable.
        // If not, give feedback!
        $logFolder = $this->config->getLogDir();
        if (is_writeable($logFolder) === false) {
            $logFolder = $this->fileService->filterFilePath($logFolder);
            $this->messages->addMessage('logNotWritable', array($logFolder));
            // Tell the chunk output that we have no write access in the logging
            // folder.
            $this->chunks->setUseLogging(false);
        }

        // At this point, we won't inform the dev right away. The error message
        // will pop up, when kreXX is actually displayed, no need to bother the
        // dev just now.
    }
105652
protected function checkPermissions()
    {
        $projectParentDirectory = dirname($this->projectDir);

        if (!is_writable($projectParentDirectory)) {
            throw new IOException(sprintf('Installer does not have enough permissions to write to the "%s" directory.', $projectParentDirectory));
        }

        return $this;
    }
1152358
protected function createLogsFile($file)
    {
        $directory = dirname($file);

        // Create directory
        if (!$this->files->isDirectory($directory)) {
            $this->files->createDir($directory);
        }

        // Create file
        if (!$this->files->has($file)) {
            $this->files->put($file, '');
        }
    }
483896
private function doSetPermissions(): void
    {
        $permissionMethod = $this->getConfig(Option::permissionMethod);
        $writableDirs = implode(' ', $this->getConfig(Option::writableDirs));
        $this->log(sprintf('<h2>Setting permissions for writable dirs using the "%s" method</>', $permissionMethod));

        if ('chmod' === $permissionMethod) {
            $this->runRemote(sprintf('chmod -R %s %s', $this->getConfig(Option::permissionMode), $writableDirs));

            return;
        }

        if ('chown' === $permissionMethod) {
            $this->runRemote(sprintf('sudo chown -RL %s %s', $this->getConfig(Option::permissionUser), $writableDirs));

            return;
        }

        if ('chgrp' === $permissionMethod) {
            $this->runRemote(sprintf('sudo chgrp -RH %s %s', $this->getConfig(Option::permissionGroup), $writableDirs));

            return;
        }

        if ('acl' === $permissionMethod) {
            $this->runRemote(sprintf('sudo setfacl -RL -m u:"%s":rwX -m u:`whoami`:rwX %s', $this->getConfig(Option::permissionUser), $writableDirs));
            $this->runRemote(sprintf('sudo setfacl -dRL -m u:"%s":rwX -m u:`whoami`:rwX %s', $this->getConfig(Option::permissionUser), $writableDirs));

            return;
        }

        throw new InvalidConfigurationException(sprintf('The "%s" permission method is not valid. Select one of the supported methods.', $permissionMethod));
    }
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?");
  }
1271773
public function getCreateFilePermissions($path = null)
    {
        try {
            if (!isset($path)) {
                $path = DIR_FILES_UPLOADED_STANDARD;
            }

            if (!is_dir($path)) {
                $path = @dirname($path);
            }
            $perms = @fileperms($path);

            if (!$perms) {
                throw new Exception(t('An error occurred while attempting to determine file permissions.'));
            }
            clearstatcache();
            $dir_perms = substr(decoct($perms), 1);

            $file_perms = "0";
            $parts[] = substr($dir_perms, 1, 1);
            $parts[] = substr($dir_perms, 2, 1);
            $parts[] = substr($dir_perms, 3, 1);
            foreach ($parts as $p) {
                if (intval($p) % 2 == 0) {
                    $file_perms .= $p;
                    continue;
                }
                $file_perms .= intval($p) - 1;
            }
        } catch (Exception $e) {
            return false;
        }
        $res = new \stdClass();
        $res->file = intval($file_perms, 8);
        $res->dir = intval($dir_perms, 8);

        return $res;
    }
864804
public function checkFilesystem()
    {
        $results = array(
            $this->checkPermissions(GC_FILE_CONFIG_COMPILED)
        );

        if (file_exists(GC_FILE_CONFIG_COMPILED_OVERRIDE)) {
            $results[] = $this->checkPermissions(GC_FILE_CONFIG_COMPILED_OVERRIDE);
        }

        $filtered = array_filter($results, 'is_string');
        return empty($filtered) ? true : $filtered;
    }
199341
protected function open_log_file() {

        if ($this->log_file) {

            if ($this->log_file_handle) {
                fclose($this->log_file_handle);
            }

            $this->log_file_handle = @fopen($this->config['log_file'], "a");
            if (!$this->log_file_handle) {
                $this->show_help("Could not open log file {$this->config['log_file']}");
            }
        }

    }
1072666
public function checkCreateFile($filePath)
    {
        $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();

        if (file_exists($filePath)) {
            if (!is_writable($filePath) && !in_array($this->getPermissionUtils()->getCurrentPermission($filePath), array($defaultPermissions['file'], $defaultPermissions['dir']))) {
                return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
            }
            return true;
        }

        $pathParts = pathinfo($filePath);
        if (!file_exists($pathParts['dirname'])) {
            $dirPermission = $defaultPermissions['dir'];
            $dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;

            if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
                throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
            }
        }

        if (touch($filePath)) {
            return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
        }

        return false;
    }
122580
public function check_storage()
    {

        $this->line(' * Checking storage');
        if (! File::isWritable(storage_path()))
            $this->error(storage_path() . ' is not writable');
        else
            $this->info(storage_path() . ' is writable');

        if (! File::isWritable(config('eveapi.config.eseye_logfile')))
            $this->error(config('eveapi.config.eseye_logfile') . ' is not writable');
        else
            $this->info(config('eveapi.config.eseye_logfile') . ' is writable');

        if (! File::isWritable(config('eveapi.config.eseye_cache')))
            $this->error(config('eveapi.config.eseye_cache') . ' is not writable');
        else
            $this->info(config('eveapi.config.eseye_cache') . ' is writable');

        if (! File::isWritable(storage_path() . '/sde/'))
            $this->error(storage_path() . '/sde/' . ' is not writable');
        else
            $this->info(storage_path() . '/sde/' . ' is writable');

        if (! File::isWritable(storage_path(sprintf('logs/laravel-%s.log', carbon()->toDateString()))))
            $this->error(storage_path(sprintf('logs/laravel-%s.log  is not writable', carbon()->toDateString())));
        else
            $this->info(storage_path(sprintf('logs/laravel-%s.log is writable', carbon()->toDateString())));
    }
177715
private function checkPermission()
    {
        // creates system acl
        $acl = $this->initAcl();

        $identity = $this->getUser()->getIdentity();
        $permissions = $this->initPermissions($identity);
        foreach ($permissions as $key => $p) {
            if ($p && $acl->hasResource($key)) {
                $acl->allow($identity->roles[0], $key, Nette\Security\Permission::ALL);
            }
        }

        // homepage and login page can access everyone
        $acl->allow(Nette\Security\Permission::ALL, 'admin:Homepage', Nette\Security\Permission::ALL);
        $acl->allow(Nette\Security\Permission::ALL, 'admin:Login', Nette\Security\Permission::ALL);

        // superadmin has access to everywhere
        $acl->allow('superadmin', Nette\Security\Permission::ALL, Nette\Security\Permission::ALL);

        $roles = $this->getUser()->getRoles();

        if (!$this->checkRights($acl, $roles)) {
            $this->presenter->flashMessage($this->translation['You do not have a permission to do this operation!'], 'danger');
            $this->redirect(":Admin:Homepage:");
        }
    }
243034
public function setApplicationPermissions()
    {
        $files = (array) $this->config->getContextually('remote.permissions.files');
        foreach ($files as &$file) {
            $this->modulable->setPermissions($file);
        }

        return true;
    }
307839
function checkAndOrCreateDir($dir, $create = false, $perm = '0777')
    {
        if(is_dir($dir) && is_writable($dir)) return true;
        elseif($create === false) return false;

        @mkdir($dir, $perm, true);
        @chmod($dir, $perm);

        if(is_writable($dir)) return true;
        return false;
    }