Skip to content

Commit 6f4e9ca

Browse files
authored
Update Unpacker.php
read the json file once
1 parent 5fedaf8 commit 6f4e9ca

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Unpacker.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function unpack(Operation $op, Result $result = null): Result
115115
public function updateLock(Result $result, IOInterface $io): void
116116
{
117117
$json = new JsonFile(Factory::getComposerFile());
118+
$jsonContent = file_get_contents($json->getPath());
118119
$manipulator = new JsonConfigSource($json);
119120
$locker = $this->composer->getLocker();
120121
$lockData = $locker->getLockData();
@@ -135,7 +136,7 @@ public function updateLock(Result $result, IOInterface $io): void
135136
}
136137
$lockData['packages'] = array_values($lockData['packages']);
137138
$lockData['packages-dev'] = array_values($lockData['packages-dev']);
138-
$lockData['content-hash'] = $locker->getContentHash(file_get_contents($json->getPath()));
139+
$lockData['content-hash'] = $locker->getContentHash($jsonContent);
139140
$lockFile = new JsonFile(substr($json->getPath(), 0, -4).'lock', null, $io);
140141

141142
if (!$this->dryRun) {
@@ -144,9 +145,9 @@ public function updateLock(Result $result, IOInterface $io): void
144145

145146
// force removal of files under vendor/
146147
if (version_compare('2.0.0', PluginInterface::PLUGIN_API_VERSION, '>')) {
147-
$locker = new Locker($io, $lockFile, $this->composer->getRepositoryManager(), $this->composer->getInstallationManager(), file_get_contents($json->getPath()));
148+
$locker = new Locker($io, $lockFile, $this->composer->getRepositoryManager(), $this->composer->getInstallationManager(), $jsonContent);
148149
} else {
149-
$locker = new Locker($io, $lockFile, $this->composer->getInstallationManager(), file_get_contents($json->getPath()));
150+
$locker = new Locker($io, $lockFile, $this->composer->getInstallationManager(), $jsonContent);
150151
}
151152
$this->composer->setLocker($locker);
152153
}

0 commit comments

Comments
 (0)