Skip to content

Commit 868e934

Browse files
committed
added buildHashedPath
1 parent 79c7b0f commit 868e934

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/models/Storage.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public function writePackage(AssetPackage $package)
7676
];
7777
$json = Json::encode($data);
7878
$hash = hash('sha256', $json);
79-
$path = $this->buildPackagePath($name, $hash);
79+
$path = $this->buildHashedPath($name, $hash);
8080
if (!file_exists($path)) {
8181
$this->getLocker()->lock();
8282
{
8383
static::mkdir(dirname($path));
8484
file_put_contents($path, $json);
85-
file_put_contents($this->buildPackagePath($name), $json);
85+
file_put_contents($this->buildHashedPath($name), $json);
8686
$this->writeProviderLatest($name, $hash);
8787
}
8888
$this->getLocker()->release();
@@ -94,7 +94,7 @@ public function writePackage(AssetPackage $package)
9494
public function readPackage(AssetPackage $package)
9595
{
9696
$name = $package->getFullName();
97-
$path = $this->buildPackagePath($name);
97+
$path = $this->buildHashedPath($name);
9898
if (!file_exists($path)) {
9999
return [];
100100
}
@@ -114,14 +114,14 @@ public function buildPath()
114114
return implode(DIRECTORY_SEPARATOR, $args);
115115
}
116116

117-
public function buildPackagePath($name, $hash = 'latest')
117+
public function buildHashedPath($name, $hash = 'latest')
118118
{
119119
return $this->buildPath('p', $name, $hash . '.json');
120120
}
121121

122122
protected function writeProviderLatest($name, $hash)
123123
{
124-
$latest_path = $this->buildPath('provider-latest.json');
124+
$latest_path = $this->buildHashedPath('provider-latest');
125125
if (file_exists($latest_path)) {
126126
$data = Json::decode(file_get_contents($latest_path) ?: '[]');
127127
}
@@ -134,12 +134,13 @@ protected function writeProviderLatest($name, $hash)
134134
$data['providers'][$name] = ['sha256' => $hash];
135135
$json = Json::encode($data);
136136
$hash = hash('sha256', $json);
137-
$path = $this->buildPath('p', "provider-latest$$hash.json");
137+
$path = $this->buildHashedPath('provider-latest', $hash);
138138
if (!file_exists($path)) {
139139
$this->getLocker()->lock();
140140
{
141+
static::mkdir(dirname($path));
141142
file_put_contents($path, $json);
142-
file_put_contents($latest_path, Json::encode($data));
143+
file_put_contents($latest_path, $json);
143144
$this->writePackagesJson($hash);
144145
}
145146
$this->getLocker()->release();
@@ -154,7 +155,7 @@ protected function writePackagesJson($hash)
154155
'search' => '/search.json?q=%query%',
155156
'providers-url' => '/p/%package%/%hash%.json',
156157
'provider-includes' => [
157-
'p/provider-latest$%hash%.json' => [
158+
'p/provider-latest/%hash%.json' => [
158159
'sha256' => $hash,
159160
],
160161
],

0 commit comments

Comments
 (0)