Skip to content

Commit 8432a30

Browse files
[6.x] Make Glide cache permissions configurable (#15920)
Co-authored-by: Amp <amp@ampcode.com>
1 parent d4e9146 commit 8432a30

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎config/assets.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@
6262
'cache' => false,
6363
'cache_path' => public_path('img'),
6464

65+
/*
66+
|--------------------------------------------------------------------------
67+
| Cached Image Permissions
68+
|--------------------------------------------------------------------------
69+
|
70+
| The permissions given to the directories and files Glide creates when
71+
| caching manipulated images to the local filesystem. Directory
72+
| permissions are still subject to the process's umask.
73+
|
74+
*/
75+
76+
'permissions' => [
77+
'directory' => 0755,
78+
'file' => 0644,
79+
],
80+
6581
/*
6682
|--------------------------------------------------------------------------
6783
| Image Manipulation Defaults

‎src/Imaging/GlideManager.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ private function localCacheFilesystem()
6565
'driver' => 'local',
6666
'root' => $root,
6767
'visibility' => 'public',
68+
'permissions' => [
69+
'file' => ['public' => Config::get('statamic.assets.image_manipulation.permissions.file')],
70+
'dir' => ['public' => Config::get('statamic.assets.image_manipulation.permissions.directory')],
71+
],
6872
]);
6973
}
7074

‎tests/Imaging/GlideTest.php‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,35 @@ public function cache_true_will_make_a_filesystem_using_the_cache_path_location(
8989
$this->assertEquals('/imgs', Glide::url());
9090
}
9191

92+
/**
93+
* @see https://github.com/statamic/cms/issues/8199
94+
*/
95+
#[Test]
96+
public function local_cache_uses_configured_permissions()
97+
{
98+
$this->markTestSkippedInWindows('Windows does not support Unix file permissions.');
99+
100+
config([
101+
'statamic.assets.image_manipulation.cache' => true,
102+
'statamic.assets.image_manipulation.cache_path' => public_path('img'),
103+
'statamic.assets.image_manipulation.permissions' => [
104+
'directory' => 0775,
105+
'file' => 0664,
106+
],
107+
]);
108+
109+
$umask = umask(0002);
110+
111+
try {
112+
Glide::cacheDisk()->put('foo/bar.jpg', 'image');
113+
} finally {
114+
umask($umask);
115+
}
116+
117+
$this->assertEquals('0775', substr(sprintf('%o', fileperms(public_path('img/foo'))), -4));
118+
$this->assertEquals('0664', substr(sprintf('%o', fileperms(public_path('img/foo/bar.jpg'))), -4));
119+
}
120+
92121
#[Test]
93122
public function hybrid_caching_will_make_a_filesystem_using_the_cache_path_location()
94123
{

0 commit comments

Comments
 (0)