Commit f087cedd authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-641 Make sure CleanStates does not touch permanent

backend storage files, unless we really want to delete them.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 30d04949
......@@ -175,6 +175,11 @@ class FileStateMachine implements IStateMachine {
* @throws StateInvalidException
*/
public function CleanStates($devid, $type, $key, $counter = false) {
// Don't remove permanent backend storage files, unless we explicitily want that
if ($key === false && $type === IStateMachine::BACKENDSTORAGE && $counter != IStateMachine::HIGHEST_COUNTER) {
return;
}
$matching_files = glob($this->getFullFilePath($devid, $type, $key). "*", GLOB_NOSORT);
if (is_array($matching_files)) {
foreach($matching_files as $state) {
......
......@@ -60,6 +60,7 @@ interface IStateMachine {
const FAILSAVE = "fs";
const HIERARCHY = "hc";
const BACKENDSTORAGE = "bs";
const HIGHEST_COUNTER = 99999999999;
const STATEVERSION_01 = "1"; // Z-Push 2.0.x - default value if unset
const STATEVERSION_02 = "2"; // Z-Push 2.1.0 Milestone 1
......
......@@ -282,7 +282,7 @@ class ZPushAdmin {
StateManager::UnLinkState($device, false);
// remove backend storage permanent data
ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, 99999999999);
ZPush::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, false, IStateMachine::HIGHEST_COUNTER);
// remove devicedata and unlink user from device
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