+
+ // Is the file's header initialized?
+ if (!$this->getIteratorInstance()->getBinaryFileInstance()->isFileHeaderInitialized()) {
+ // First pre-allocate a bit
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Invoking this->iteratorInstance->preAllocateFile(file_stack) ...');
+ $this->getIteratorInstance()->getBinaryFileInstance()->preAllocateFile('file_stack');
+
+ // Then create file header
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: this->iteratorInstance->createFileHeader() ...');
+ $this->getIteratorInstance()->getBinaryFileInstance()->createFileHeader();
+ }
+
+ // Load the file header
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Invoking this->readStackHeader() ...');
+ $this->readStackHeader();
+
+ // Is the index loaded correctly, e.g. the stack file is just created?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Invoking this->indexInstance->isIndexLoaded() ...');
+ if (!$this->getIndexInstance()->isIndexLoaded()) {
+ /*
+ * Something horrible has happened to the index as it should be
+ * loaded at this point. The stack's file structure then needs to
+ * be analyzed and the index rebuild.
+ */
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: Invoking this->iteratorInstance->analyzeFileStructure() ...');
+ $this->getIteratorInstance()->getBinaryFileInstance()->analyzeFileStructure();
+
+ // Rebuild index from file
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-FILE-STACK: Invoking this->iteratorInstance->rebuildIndexFromStack(%s) ...', $this->__toString()));
+ $this->getIndexInstance()->rebuildIndexFromStack($this);
+ }
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-FILE-STACK: EXIT!');