]> git.mxchange.org Git - core.git/commitdiff
Introduced seekToOldPosition() and avoided endless loop.
authorRoland Haeder <roland@mxchange.org>
Tue, 20 May 2014 19:41:41 +0000 (21:41 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 20 May 2014 19:41:41 +0000 (21:41 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/index/class_BaseIndex.php
inc/classes/main/stacker/file/class_BaseFileStack.php

index 161710f552f119e0faa8ceefb0c3288cfa5e91fe..06f3a4d6d6debc47f5201b4ad1fa3c9df52f4207 100644 (file)
@@ -3057,14 +3057,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
        }
 
+       /**
+        * Seeks to old position
+        *
+        * @return      void
+        */
+       protected function seekToOldPosition () {
+               // Seek to currently ("old") saved position
+               $this->getIteratorInstance()->seek($this->getSeekPosition());
+       }
+
        /**
         * Writes data at given position
         *
         * @param       $seekPosition   Seek position
         * @param       $data                   Data to be written
+        * @param       $flushHeader    Whether to flush the header (default: flush)
         * @return      void
         */
-       protected function writeData ($seekPosition, $data) {
+       protected function writeData ($seekPosition, $data, $flushHeader = TRUE) {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%s - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
 
                // Write data at given position
@@ -3073,8 +3084,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Update seek position
                $this->updateSeekPosition();
 
-               // Flush header
-               $this->flushFileHeader();
+               // Flush the header?
+               if ($flushHeader === TRUE) {
+                       // Flush header
+                       $this->flushFileHeader();
+               } // END - if
 
                // Seek to old position
                $this->seekToOldPosition();
index fe16473e4b94dfe32ee950751d7d291476f86c07..29d0d52e10246f3824cb1db90afda4dae80c201d 100644 (file)
@@ -128,16 +128,22 @@ class BaseIndex extends BaseFrameworkSystem {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] CALLED!', __METHOD__, __LINE__));
 
                // Put all informations together
-               $header = sprintf('%s%s',
+               $header = sprintf('%s%s%s%s',
                        // Magic
                        self::INDEX_MAGIC,
 
-                       // Separator position<->entries
+                       // Separator header data
+                       chr(self::SEPARATOR_HEADER_DATA),
+
+                       // Total entries
+                       str_pad($this->dec2hex($this->getCounter()), self::LENGTH_COUNT, '0', STR_PAD_LEFT),
+
+                       // Separator header<->entries
                        chr(self::SEPARATOR_HEADER_ENTRIES)
                );
 
                // Write it to disk (header is always at seek position 0)
-               $this->writeData(0, $header);
+               $this->writeData(0, $header, FALSE);
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }
index 2a169bce4e926704e76ad4e8f32da26d9ebd2340..9b662aac46381b993ece22b261da677a7004bdca 100644 (file)
@@ -165,7 +165,7 @@ class BaseFileStack extends BaseStacker {
                );
 
                // Write it to disk (header is always at seek position 0)
-               $this->writeData(0, $header);
+               $this->writeData(0, $header, FALSE);
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
        }