Futilities/v0.6/clade/Sys/IO/Store/Spider/@fx/OnWantedFolder

From WoozleCodes
Jump to navigation Jump to search

History

  • 2024-04-28 There's a conflict between the intent of ShowProgress() -- which logs to the screen -- and the way some apps keep a fixed-position readout-block on the screen.
  • 2024-05-02 Commenting out ShowProgress stuff until we have a clear need-case.
  • 2026-05-02 TODO: We need a way to preserve number of files found, so top level call can report if none.
  • 2026-05-06 I've moved most of the code here into $oPair->ListSubs().

Code

#
    protected function OnWantedFolder(FoNodeIface $of) {
      #echo $op->ReflectThis()->Report();
        #$this->AmHere('SPEC=['.$op->QSPath()->GetIt().']');

        #$om = $this->GetMatcher();
        #$oOpts = $om->OOptions;
        #$doSP = $oOpts->ShowProgress();
        #$ofLog = $oOpts->LogFile();

        // log entering (checking) the folder
        $this->LogSourceFolder($of);


        // TODO 2026-05-02 Convert this to use [WFe]Sys\FileSys\Aspect\InOut\Fo

        // read the active directory
        #echo $op->ReflectThis()->Report();
        #$ofDir = $op->OFNode()->InOut()->ContentArray();

        // Create a file-node object for the filespec:
        $ofDir = FNodeAdmin::FromSpec($of->QSPath()->GetIt());
        // (Assume is folder) Get directory listing:
        $oaDir = $ofDir->InOut()->ContentArray();

        /*
        // iterate through directory of this folder and copy to array
        $arList = [];
        while (FALSE !== ($fn = $od->read())) {
            // exclude utility entries
            if (($fn != '.') and ($fn != '..')) {
                $arList[] = $fn;
            }
        }
        $od->close();
        */
        if (count($oaDir) > 0) {
            $aList = [];
            $afDir = $oaDir->GetVals();
            foreach ($afDir as $oFi) {
                #$fs = $oFi->Ident()->OSpec()->QSPath()->GetIt();
                $fs = $oFi->Ident()->SpecFull();
                $aList[$fs] = $oFi;
            }

            // sorting the files makes progress easier to perceive in large folders
            ksort($aList);

            foreach ($aList as $fs => $oNode) {
                if (is_link($fs)) {
                    // skip linked folders
                    $this->Logger()->WriteLn("[DEBUG] LINK SKIPPED: $fs");
                } else {
                    // process it recursively
                    $this->OnPath($oNode);
                }
            }

            /* 2026-05-04 obsolete
            $opDir = new PathListClass($op,$arList);
            $opDir->DoReset();
            while ($opDir->GoNext()) {
                $osFS = $opDir->GetPathStatus();
                #$fsr = $osFS->GetRelPath();
                #$fsa = $osFS->GetAbsPath();
                $oInfo = $opDir->Info();
                $fs = $oInfo->Raw();
                if ($oInfo->IsLink()) {
                  // never go into linked folders
                  $oLog->WriteLn("[DEBUG] LINK SKIPPED: $fs");
                } else {

                  #$ofLog->WriteLn("[DEBUG] not a link: $fs");

                    // process it recursively
                    $this->OnPath($opDir);
                }
            }
            */
        }
    }