Skip to content

Commit 80c74cc

Browse files
bug #587 compare data before marking lock as changed (stlrnz)
This PR was squashed before being merged into the 1.5-dev branch. Discussion ---------- compare data before marking lock as changed In #479 I tried to fix the issue #379 by introducing a _changed_ flag to the Lock. This patch worked for a few months. However, introducing #576 broke the patch by [always calling](https://github.com/symfony/flex/pull/576/files#diff-46b78198ae7ea525f04268205dd782c3R273) `set` ending in the same situation as before. Blame on me for not checking if anything differs before setting the _changed_ flag. This PR tries to do better. Commits ------- bc400be compare data before marking lock as changed
2 parents d67eb5d + bc400be commit 80c74cc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Lock.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,18 @@ public function get($name)
4949

5050
public function set($name, $data)
5151
{
52-
$this->lock[$name] = $data;
53-
$this->changed = true;
52+
if (!\array_key_exists($name, $this->lock) || $data !== $this->lock[$name]) {
53+
$this->lock[$name] = $data;
54+
$this->changed = true;
55+
}
5456
}
5557

5658
public function remove($name)
5759
{
58-
unset($this->lock[$name]);
59-
$this->changed = true;
60+
if (\array_key_exists($name, $this->lock)) {
61+
unset($this->lock[$name]);
62+
$this->changed = true;
63+
}
6064
}
6165

6266
public function write()

0 commit comments

Comments
 (0)