From 5be92ee0bc0cba46404a391f569367bf2a2b6292 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 20 May 2014 21:41:41 +0200 Subject: [PATCH] Introduced seekToOldPosition() and avoided endless loop. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../main/class_BaseFrameworkSystem.php | 20 ++++++++++++++++--- inc/classes/main/index/class_BaseIndex.php | 12 ++++++++--- .../main/stacker/file/class_BaseFileStack.php | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 161710f5..06f3a4d6 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -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(); diff --git a/inc/classes/main/index/class_BaseIndex.php b/inc/classes/main/index/class_BaseIndex.php index fe16473e..29d0d52e 100644 --- a/inc/classes/main/index/class_BaseIndex.php +++ b/inc/classes/main/index/class_BaseIndex.php @@ -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__)); } diff --git a/inc/classes/main/stacker/file/class_BaseFileStack.php b/inc/classes/main/stacker/file/class_BaseFileStack.php index 2a169bce..9b662aac 100644 --- a/inc/classes/main/stacker/file/class_BaseFileStack.php +++ b/inc/classes/main/stacker/file/class_BaseFileStack.php @@ -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__)); } -- 2.39.2