Check the file system, triggered by timer
@return void
169928
public function watch()
    {
        if ($this->inotify) {
            $events = inotify_read($this->inotify);
            if (!$events) {
                return;
            }
            foreach ($events as $ev) {
                $path = $this->descriptors[$ev['wd']];
                if (!isset($this->files[$path])) {
                    continue;
                }
                $this->onFileChanged($path);
            }
        } else {
            static $hash = [];

            foreach ($this->files as $path => $v) {
                if (!file_exists($path)) {
                    // file can be deleted
                    unset($this->files[$path]);
                    continue;
                }

                $mt = filemtime($path);

                if (isset($hash[$path]) && ($mt > $hash[$path])) {
                    $this->onFileChanged($path);
                }

                $hash[$path] = $mt;
            }
        }
    }
816430
public function verify()
    {
        $files     = $this->filesystem->allFiles(base_path('src'));
        $memory    = app('antares.memory')->make('checksum');
        $checksums = $memory->all();
        $updates   = [];
        $allFiles  = [];
        foreach ($files as $file) {
            $key            = $file->getRelativePath() . DIRECTORY_SEPARATOR . $file->getFilename();
            $checksum       = md5_file($file->getRealPath());
            $allFiles[$key] = $checksum;
            if (isset($checksums[$key]) && $checksums[$key] !== $checksum) {
                $updates[$key] = $checksum;
            }
        }
        $inserts = array_diff(array_keys($allFiles), array_keys($checksums));
        $deletes = array_diff(array_keys($checksums), array_keys($allFiles));

        $return = ['inserts' => $inserts, 'updates' => $updates, 'deletes' => $deletes];
        $this->validate($return);
        return $return;
    }
205919
protected function checkStoragePermission()
    {
        Session::checkServicePermission(
            Verbs::POST, $this->storageService, trim($this->storageFolder, '/'), Session::getRequestor()
        );
    }
652690
public function check()
    {
        $origStage = Versioned::get_reading_mode();
        Versioned::set_reading_mode(Versioned::LIVE);

        $files = $this->getFiles();
        if ($files) {
            $fileTypeValidateFunc = $this->fileTypeValidateFunc;
            if (method_exists($this, $fileTypeValidateFunc)) {
                $invalidFiles = [];
                $validFiles = [];

                foreach ($files as $file) {
                    if ($this->$fileTypeValidateFunc($file)) {
                        $validFiles[] = $file;
                    } else {
                        $invalidFiles[] = $file;
                    }
                }

                // If at least one file was valid, count as passed
                if ($this->checkType == self::CHECK_SINGLE && count($invalidFiles) < count($files)) {
                    $validFileList = PHP_EOL;
                    foreach ($validFiles as $vf) {
                        $validFileList .= $vf . PHP_EOL;
                    }
                    if ($fileTypeValidateFunc == 'noVidation') {
                        $checkReturn = [
                            EnvironmentCheck::OK,
                            sprintf('At least these file(s) accessible: %s', $validFileList)
                        ];
                    } else {
                        $checkReturn = [
                            EnvironmentCheck::OK,
                            sprintf(
                                'At least these file(s) passed file type validate function "%s": %s',
                                $fileTypeValidateFunc,
                                $validFileList
                            )
                        ];
                    }
                } else {
                    if (count($invalidFiles) == 0) {
                        $checkReturn = [EnvironmentCheck::OK, 'All files valideted'];
                    } else {
                        $invalidFileList = PHP_EOL;
                        foreach ($invalidFiles as $vf) {
                            $invalidFileList .= $vf . PHP_EOL;
                        }

                        if ($fileTypeValidateFunc == 'noVidation') {
                            $checkReturn = [
                                EnvironmentCheck::ERROR,
                                sprintf('File(s) not accessible: %s', $invalidFileList)
                            ];
                        } else {
                            $checkReturn = [
                                EnvironmentCheck::ERROR,
                                sprintf(
                                    'File(s) not passing the file type validate function "%s": %s',
                                    $fileTypeValidateFunc,
                                    $invalidFileList
                                )
                            ];
                        }
                    }
                }
            } else {
                $checkReturn =  array(
                    EnvironmentCheck::ERROR,
                    sprintf("Invalid file type validation method name passed: %s ", $fileTypeValidateFunc)
                );
            }
        } else {
            $checkReturn = array(
                EnvironmentCheck::ERROR,
                sprintf("No files accessible at path %s", $this->path)
            );
        }

        Versioned::set_reading_mode($origStage);

        return $checkReturn;
    }
127331
protected function fileExists()
    {
        $this->clearStatCache(true);
        return (file_exists($this->file_path) && is_file($this->file_path));
    }
245456
protected function checkProcessStatus(): void
    {
        $this->logProcessStandardStreams();

        $process = $this->process;

        if (!empty($process->getErrorOutput())) {
            if (IdleTimeoutException::exceptionApplies($process)) {
                throw new IdleTimeoutException(
                    $this->options['idle_timeout'],
                    new NodeFatalException($process, $this->options['debug'])
                );
            } else if (NodeFatalException::exceptionApplies($process)) {
                throw new NodeFatalException($process, $this->options['debug']);
            } elseif ($process->isTerminated() && !$process->isSuccessful()) {
                throw new ProcessFailedException($process);
            }
        }

        if ($process->isTerminated()) {
            throw new Exceptions\ProcessUnexpectedlyTerminatedException($process);
        }
    }
44403
private function setFilesMtime()
  {
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->myWorkDirName,
                                                                          FilesystemIterator::UNIX_PATHS));
    foreach ($files as $full_path => $file)
    {
      if ($file->isFile())
      {
        $key = substr($full_path, strlen($this->myWorkDirName.'/'));
        if (isset($this->myLastCommitTimes[$key]))
        {
          $this->logVerbose("Set mtime of %s to %s", $full_path, date('Y-m-d H:i:s', $this->myLastCommitTimes[$key]));
          $success = touch($full_path, $this->myLastCommitTimes[$key]);
          if (!$success)
          {
            $this->logError("Unable to set mtime of file %s", $full_path);
          }

          $this->myCount++;
        }
      }
    }
  }
876885
public function actionStatus()
    {
        $pid = $this->getMasterPid();
        Console::stdout("beyod($pid) is running ...\r\n");
        Console::stdout("php ini: ".php_ini_loaded_file()."\r\n");
        Console::stdout("php version: ".phpversion()."\r\n");
        Console::stdout("necessary extensions status:\r\n");
        foreach(['pcntl', 'event', 'posix'] as $ext){
            Console::stdout("\t$ext: \t". (extension_loaded($ext) ? 'yes':'no')."\r\n");
        }
    }
527203
protected function checkRuntime()
    {
        // Check Runtime.
        if ($this->timer < time()) {
            // This is taking longer than expected.
            $this->pool->messages->addMessage('emergencyTimer');
            Krexx::editSettings();
            Krexx::disable();
            static::$allIsOk = false;
            return true;
        }

        return false;
    }
657689
public function process()
    {
        $this->report->deleteExpired();
        $this->history->deleteExpired();

        // Delete files in temporary directory
        foreach (gplcart_file_scan_recursive(GC_DIR_PRIVATE_TEMP) as $file) {
            if (strpos(basename($file), '.') !== 0) { // Ignore hidden files
                gplcart_file_delete_recursive($file);
            }
        }

        $result = $this->report->checkFilesystem();

        if ($result !== true) {
            foreach ((array) $result as $message) {
                $this->logger->log('system_status', array('message' => $message), 'warning');
            }
        }

        return true;
    }
314217
public function run()
    {
        $this->loader->parse();
        $files = $this->filesystem->getFiles();

        // Now we check all the files against the config
        while ($files->valid()) {
            /* @var SplFileInfo $file */
            $file = $files->current();

            // Skip symlinks as they are always 0777
            if ($file->isLink()) {
                $files->next();
                continue;
            }

            $filename = $this->getRelativeFilename($file);

            // Skip excluded files, of course.
            if ($this->isExcluded($filename)) {
                $files->next();
                continue;
            }

            $fileShouldBeExecutable = $this->shouldBeExecutable($filename);
            if (!$fileShouldBeExecutable && $file->isExecutable()) {
                $this->messageBag->addMessage($file->getPathname(), 'minx');
                $files->next();
                continue;
            }

            if ($fileShouldBeExecutable && !$file->isExecutable()) {
                $this->messageBag->addMessage($file->getPathname(), 'plusx');
                $files->next();
                continue;
            }

            $files->next();
        }
    }
1218774
protected function execute_condition() {

        // Check it is included in the backup
        $fullpath = $this->task->get_taskbasepath();
        $fullpath = rtrim($fullpath, '/') . '/' . $this->filename;
        if (!file_exists($fullpath)) {
            // Not found, can't restore course logs
            return false;
        }

        return true;
    }
1029770
protected function _checkArchivers()
    {
        if (!function_exists('exec')) {
            $this->options['archivers'] = $this->options['archive'] = array();

            return;
        }
        $arcs = array(
            'create'  => array(),
            'extract' => array()
            );

        //exec('tar --version', $o, $ctar);
        $this->procExec('tar --version', $o, $ctar);

        if ($ctar == 0) {
            $arcs['create']['application/x-tar']  = array('cmd' => 'tar', 'argc' => '-cf', 'ext' => 'tar');
            $arcs['extract']['application/x-tar'] = array('cmd' => 'tar', 'argc' => '-xf', 'ext' => 'tar');
            //$test = exec('gzip --version', $o, $c);
            unset($o);
            $test = $this->procExec('gzip --version', $o, $c);

            if ($c == 0) {
                $arcs['create']['application/x-gzip']  = array('cmd' => 'tar', 'argc' => '-czf', 'ext' => 'tgz');
                $arcs['extract']['application/x-gzip'] = array('cmd' => 'tar', 'argc' => '-xzf', 'ext' => 'tgz');
            }
            unset($o);
            //$test = exec('bzip2 --version', $o, $c);
            $test = $this->procExec('bzip2 --version', $o, $c);
            if ($c == 0) {
                $arcs['create']['application/x-bzip2']  = array('cmd' => 'tar', 'argc' => '-cjf', 'ext' => 'tbz');
                $arcs['extract']['application/x-bzip2'] = array('cmd' => 'tar', 'argc' => '-xjf', 'ext' => 'tbz');
            }
        }
        unset($o);
        //exec('zip --version', $o, $c);
        $this->procExec('zip -v', $o, $c);
        if ($c == 0) {
            $arcs['create']['application/zip']  = array('cmd' => 'zip', 'argc' => '-r9', 'ext' => 'zip');
        }
        unset($o);
        $this->procExec('unzip --help', $o, $c);
        if ($c == 0) {
            $arcs['extract']['application/zip'] = array('cmd' => 'unzip', 'argc' => '',  'ext' => 'zip');
        }
        unset($o);
        //exec('rar --version', $o, $c);
        $this->procExec('rar --version', $o, $c);
        if ($c == 0 || $c == 7) {
            $arcs['create']['application/x-rar']  = array('cmd' => 'rar', 'argc' => 'a -inul', 'ext' => 'rar');
            $arcs['extract']['application/x-rar'] = array('cmd' => 'rar', 'argc' => 'x -y',    'ext' => 'rar');
        } else {
            unset($o);
            //$test = exec('unrar', $o, $c);
            $test = $this->procExec('unrar', $o, $c);
            if ($c==0 || $c == 7) {
                $arcs['extract']['application/x-rar'] = array('cmd' => 'unrar', 'argc' => 'x -y', 'ext' => 'rar');
            }
        }
        unset($o);
        //exec('7za --help', $o, $c);
        $this->procExec('7za --help', $o, $c);
        if ($c == 0) {
            $arcs['create']['application/x-7z-compressed']  = array('cmd' => '7za', 'argc' => 'a', 'ext' => '7z');
            $arcs['extract']['application/x-7z-compressed'] = array('cmd' => '7za', 'argc' => 'e -y', 'ext' => '7z');

            if (empty($arcs['create']['application/x-gzip'])) {
                $arcs['create']['application/x-gzip'] = array('cmd' => '7za', 'argc' => 'a -tgzip', 'ext' => 'tar.gz');
            }
            if (empty($arcs['extract']['application/x-gzip'])) {
                $arcs['extract']['application/x-gzip'] = array('cmd' => '7za', 'argc' => 'e -tgzip -y', 'ext' => 'tar.gz');
            }
            if (empty($arcs['create']['application/x-bzip2'])) {
                $arcs['create']['application/x-bzip2'] = array('cmd' => '7za', 'argc' => 'a -tbzip2', 'ext' => 'tar.bz');
            }
            if (empty($arcs['extract']['application/x-bzip2'])) {
                $arcs['extract']['application/x-bzip2'] = array('cmd' => '7za', 'argc' => 'a -tbzip2 -y', 'ext' => 'tar.bz');
            }
            if (empty($arcs['create']['application/zip'])) {
                $arcs['create']['application/zip'] = array('cmd' => '7za', 'argc' => 'a -tzip -l', 'ext' => 'zip');
            }
            if (empty($arcs['extract']['application/zip'])) {
                $arcs['extract']['application/zip'] = array('cmd' => '7za', 'argc' => 'e -tzip -y', 'ext' => 'zip');
            }
            if (empty($arcs['create']['application/x-tar'])) {
                $arcs['create']['application/x-tar'] = array('cmd' => '7za', 'argc' => 'a -ttar -l', 'ext' => 'tar');
            }
            if (empty($arcs['extract']['application/x-tar'])) {
                $arcs['extract']['application/x-tar'] = array('cmd' => '7za', 'argc' => 'e -ttar -y', 'ext' => 'tar');
            }
        }

        $this->archivers = $arcs;
    }
669258
public function main()
    {

        // load the interval we want to scan the directory
        $interval = $this->getInterval();

        // load the configured directory
        $directory = $this->getDirectory();

        // prepare the extensions of the file we want to watch
        $extensionsToWatch = sprintf('{%s}', implode(',', $this->getExtensionsToWatch()));

        // log the configured deployment directory
        $this->getSystemLogger()->info(
            sprintf('Start scanning directory %s for files to be rotated (interval %d)', $directory, $interval)
        );

        // watch the configured directory
        while (true) {
            // clear the filesystem cache
            clearstatcache();

            // iterate over the files to be watched
            foreach (glob($directory . '/*.' . $extensionsToWatch, GLOB_BRACE) as $fileToRotate) {
                // log that we're rotate the file
                $this->getSystemLogger()->debug(
                    sprintf('Query wheter it is necessary to rotate %s', $fileToRotate)
                );

                // handle file rotation
                $this->handle($fileToRotate);

                // cleanup files
                $this->cleanup($fileToRotate);
            }

            // sleep a while
            sleep($interval);
        }
    }
801893
private function checkConnection()
    {
        if ($this->_databaseServer !== self::DB_MYSQL) {
            return;
        }

        $interval = (time() - (int)$this->_lastCheckTime);

        if ($interval >= self::MYSQL_CONNECTION_TIMEOUT) {
            $this->connect();
        }
    }
420072
public function check()
    {
        $this->goodPools = getInstance()->sysCache->get($this->name) ?? [];
        if (!$this->goodPools) {
            return false;
        }

        $nowPools = $this->getAllTargets();
        $newPools = array_keys($this->goodPools);
        $loses    = array_diff($nowPools, $newPools);

        if (!empty($loses)) {
            foreach ($loses as $lost) {
                $this->removeTarget($lost);
            }
            writeln('Redis Proxy Remove ( ' . implode(',', $loses) . ' ) from Cluster');
        }

        $adds = array_diff($newPools, $nowPools);
        if (!empty($adds)) {
            foreach ($adds as $add) {
                $this->addTarget($add, $this->pools[$add]);
            }
            writeln('Redis Proxy Add ( ' . implode(',', $adds) . ' ) into Cluster');
        }

        return true;
    }
684260
protected function isExpired()
    {
        if (! $this->filesystem->exists($this->cached)) {
            return true;
        }

        $lastModified = $this->filesystem->lastModified($this->file->getPath());

        return $lastModified >= $this->filesystem->lastModified($this->cached);
    }