Skip to content

Commit f8a4af5

Browse files
ianbeuIan BeuchelCopilot
authored
Add writable_acl_force to force ACL reset on writable dirs (#4140)
* Add writable_acl_force to force ACL reset on writable dirs * Update recipe/deploy/writable.php Co-authored-by: Copilot <[email protected]> * Improve writable_acl_force setting documentation --------- Co-authored-by: Ian Beuchel <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent f8e41b6 commit f8a4af5

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.phpunit.result.cache
44
docker-compose.override.yml
55
.php-cs-fixer.cache
6+
.idea/

docs/recipe/deploy/writable.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,21 @@ List of additional groups to give write permission to.
9898

9999

100100

101+
### writable_acl_force
102+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/writable.php#L65)
103+
104+
Force ACLs to be reapplied even if they already exist. Useful when recursive ACLs need to reach new nested paths but sudo isn't available. Slower, so enable only to fix writable dir permissions.
105+
106+
```php title="Default value"
107+
false
108+
```
109+
110+
101111

102112
## Tasks
103113

104114
### deploy\:writable {#deploy-writable}
105-
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/writable.php#L65)
115+
[Source](https://github.com/deployphp/deployer/blob/master/recipe/deploy/writable.php#L68)
106116

107117
Makes writable dirs.
108118

recipe/deploy/writable.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
// List of additional groups to give write permission to.
6262
set('writable_acl_groups', []);
6363

64+
// Force ACLs to be reapplied even if they already exist. Useful when recursive ACLs need to reach new nested paths but sudo isn't available. Slower, so enable only to fix writable dir permissions.
65+
set('writable_acl_force', false);
66+
6467
desc('Makes writable dirs');
6568
task('deploy:writable', function () {
6669
$dirs = join(' ', get('writable_dirs'));
@@ -121,14 +124,16 @@
121124
if (empty($sudo)) {
122125
// When running without sudo, exception may be thrown
123126
// if executing setfacl on files created by http user (in directory that has been setfacl before).
124-
// These directories/files should be skipped.
125-
// Now, we will check each directory for ACL and only setfacl for which has not been set before.
127+
// These directories/files should be skipped unless forcing ACL reset.
128+
// Now, we will check each directory for ACL and only setfacl for which has not been set before,
129+
// unless writable_acl_force is enabled.
126130
$writeableDirs = get('writable_dirs');
131+
$forceAcl = get('writable_acl_force');
127132
foreach ($writeableDirs as $dir) {
128133
// Check if ACL has been set or not
129134
$hasfacl = run("getfacl -p $dir | grep \"^user:$httpUser:.*w\" | wc -l");
130-
// Set ACL for directory if it has not been set before
131-
if (!$hasfacl) {
135+
// Set ACL for directory if it has not been set before or if forcing ACL reset
136+
if ($forceAcl || !$hasfacl) {
132137
run("setfacl -L $recursive $setFaclUsers $setFaclGroups $dir");
133138
run("setfacl -dL $recursive $setFaclUsers $setFaclGroups $dir");
134139
}

0 commit comments

Comments
 (0)