Commit ece2e377 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #150 in ZP/z-push from...

Merge pull request #150 in ZP/z-push from bugfix/ZP-641-filestatemachine-backend-storage-file to develop

* commit '5c7a4b19':
  ZP-641 Delete file only if it exists.
  ZP-641 CleanStates() has to stop after deleting one BS file.
  ZP-641 call GetState() with the "do not clean" flag, changed CleanStates() to delete exact bs files when being calles without uuid for bs type (needs better fixing in ZP-835).

(cherry picked from commit 3f1f999e)
parent ec4280de
...@@ -300,7 +300,7 @@ class StateManager { ...@@ -300,7 +300,7 @@ class StateManager {
return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, $this->uuid, $this->oldStateCounter, $this->deleteOldStates); return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, $this->uuid, $this->oldStateCounter, $this->deleteOldStates);
} }
else { else {
return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, $this->device->GetFirstSyncTime()); return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, $this->device->GetFirstSyncTime(), false);
} }
} }
......
...@@ -176,10 +176,16 @@ class FileStateMachine implements IStateMachine { ...@@ -176,10 +176,16 @@ class FileStateMachine implements IStateMachine {
* @throws StateInvalidException * @throws StateInvalidException
*/ */
public function CleanStates($devid, $type, $key, $counter = false) { public function CleanStates($devid, $type, $key, $counter = false) {
// Don't remove permanent backend storage files, unless we explicitily want that // Remove permanent backend storage files
if ($key === false && $type === IStateMachine::BACKENDSTORAGE && $counter != IStateMachine::HIGHEST_COUNTER) { // TODO remove this block and implement it as described in ZP-835
if ($key === false && $type === IStateMachine::BACKENDSTORAGE) {
$file = $this->getFullFilePath($devid, $type, $key, $counter);
if (file_exists($file)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("FileStateMachine->CleanStates(): Deleting 'bs' file: '%s'", $file));
unlink($file);
return; return;
} }
}
$matching_files = glob($this->getFullFilePath($devid, $type, $key). "*", GLOB_NOSORT); $matching_files = glob($this->getFullFilePath($devid, $type, $key). "*", GLOB_NOSORT);
if (is_array($matching_files)) { if (is_array($matching_files)) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Z-Push implements the FileStateMachine which * Z-Push implements the FileStateMachine which
* saves states to disk. * saves states to disk.
* Backends provide their own IStateMachine * Backends provide their own IStateMachine
implementation of this interface and return * implementation of this interface and return
* an IStateMachine instance with IBackend->GetStateMachine(). * an IStateMachine instance with IBackend->GetStateMachine().
* Old sync states are not deleted until a new sync state * Old sync states are not deleted until a new sync state
* is requested. * is requested.
...@@ -60,7 +60,6 @@ interface IStateMachine { ...@@ -60,7 +60,6 @@ interface IStateMachine {
const FAILSAVE = "fs"; const FAILSAVE = "fs";
const HIERARCHY = "hc"; const HIERARCHY = "hc";
const BACKENDSTORAGE = "bs"; const BACKENDSTORAGE = "bs";
const HIGHEST_COUNTER = 99999999999;
const STATEVERSION_01 = "1"; // Z-Push 2.0.x - default value if unset const STATEVERSION_01 = "1"; // Z-Push 2.0.x - default value if unset
const STATEVERSION_02 = "2"; // Z-Push 2.1.0 Milestone 1 const STATEVERSION_02 = "2"; // Z-Push 2.1.0 Milestone 1
......
...@@ -282,7 +282,7 @@ class ZPushAdmin { ...@@ -282,7 +282,7 @@ class ZPushAdmin {
StateManager::UnLinkState($device, false); StateManager::UnLinkState($device, false);
// remove backend storage permanent data // remove backend storage permanent data
ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, IStateMachine::HIGHEST_COUNTER); ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, $device->GetFirstSyncTime());
// remove devicedata and unlink user from device // remove devicedata and unlink user from device
unset($devices[$user]); unset($devices[$user]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment