Skip to content

Commit

Permalink
bug #479 only write lock when its content has changed (stlrnz)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.2-dev branch.

Discussion
----------

only write lock when its content has changed

Fixed #379 by only writing the Lockfile when something has changed (which is not the case on `composer install`).

This seems to me the best solution for the linked issue:
* no change in the Flex behaviour on `composer install` needed (still doing the same like on `composer update`)
* only update the Lockfile when needed (even the modification timestamp will stay the same)
* working for all composer actions (because of auto detection)

Thank you for your feedback.

Commits
-------

ffe345f only write lock when its content has changed
  • Loading branch information
fabpot committed Mar 9, 2019
2 parents 7f04fb5 + ffe345f commit d4176d3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Lock
{
private $json;
private $lock = [];
private $changed = false;

public function __construct($lockFile)
{
Expand All @@ -38,6 +39,7 @@ public function add($name, $data)
{
$current = $this->lock[$name] ?? [];
$this->lock[$name] = array_merge($current, $data);
$this->changed = true;
}

public function get($name)
Expand All @@ -48,15 +50,21 @@ public function get($name)
public function set($name, $data)
{
$this->lock[$name] = $data;
$this->changed = true;
}

public function remove($name)
{
unset($this->lock[$name]);
$this->changed = true;
}

public function write()
{
if (!$this->changed) {
return;
}

if ($this->lock) {
ksort($this->lock);
$this->json->write($this->lock);
Expand Down

0 comments on commit d4176d3

Please sign in to comment.