diff --git a/.gitignore b/.gitignore
old mode 100644
new mode 100755
diff --git a/.web_package/config b/.web_package/config
old mode 100644
new mode 100755
diff --git a/.web_package/hooks/bootstrap.php b/.web_package/hooks/bootstrap.php
old mode 100644
new mode 100755
diff --git a/.web_package/hooks/build/00_docs.sh b/.web_package/hooks/build/00_docs.sh
old mode 100644
new mode 100755
diff --git a/LICENSE b/LICENSE
old mode 100644
new mode 100755
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 978a5e1..1661716
--- a/README.md
+++ b/README.md
@@ -1,23 +1,26 @@
-# Configuration
+# Easy Perms
Add this to a project to be able to easily manage file permissions.
-The files in a web app are likely to require writeable and executable permissions on some files, but not most. This tool allows you to set a baseline and then be only as permissive as necessary. The management is simply to add paths or globs to a YAML or JSON file and then run the script.
+The files in a web app are likely to require writeable and/or executable permissions on some files, but not most. It's time-consuming and may be confusing to keep these in order. This tool allows you to set a baseline and then be only as permissive as necessary. The management is simply to add paths or globs to a YAML or JSON file and then run the script.
**This project does not handle ownership of files, by design.** It assumes proper owner and group on all files, and merely sets the octal permissions.
-#* Both YAML and JSON is supported.
-* See _json_schema/config.schema.json_ for details of the configuration.
+## Configuration
+
+* Both YAML and JSON is supported.
+* See _json\_schema/config.schema.json_ for details of the configuration.
+* Notice globs are supported. So are `/**/` doubles.
+* **Directories are ALWAYS recursive.** Don't be confused because, you will not see the recursive files in the output.
+* Also, the same and same number of files are handled by `../..` and `../../*`; however with the second example you will see the glob-matched filenames in the output, so it may be more desirable to use that format.
_./bin/config/perms.yml_
```yaml
default:
- - ../..
- ../../*
writeable:
- ../../web/sites/*/files
- - ../../web/sites/*/files/*
executable:
- ../../vendor/bin/*
```
@@ -46,7 +49,7 @@ Apply permissions like this:
## What Are the Permission Values?
* See `\AKlump\ProjectPermissions\DefaultFilePermissions` and `\AKlump\ProjectPermissions\DefaultDirectoryPermissions` for default values.
-* To override these values add something like the following to your configuration file:
+* To override these values add any or all of following to your configuration file:
```yaml
file_permissions:
@@ -58,3 +61,7 @@ directory_permissions:
writeable: '0770'
executable: '0750'
```
+
+## Troubleshooting
+
+This tool may reveal invalid symlinks, which you will see in the error output at the end, and should remove to avoid further errors.
diff --git a/app.php b/app.php
index 8ef33ab..970f635 100755
--- a/app.php
+++ b/app.php
@@ -43,18 +43,20 @@
$items = Glob::glob($path);
foreach ($items as $item) {
$perms = (string) $config['file_permissions'][$type];
+ $label = Path::makeRelative($item, $START_DIR);
if (is_dir($item)) {
$perms = (string) $config['directory_permissions'][$type];
+ $label = rtrim($label, '/') . '/';
}
- $current_perms = substr(sprintf('%o', fileperms($item)), -4);
- if (strcasecmp($current_perms, $perms) !== 0) {
- try {
- $filesystem->chmod($item, $perms);
- $output->writeln($perms . ' ' . $meta['icon'] . Path::makeRelative($item, $START_DIR));
- }
- catch (IOException $exception) {
- $failures[] = sprintf('Failed to change %s to %s 😞 %s', $current_perms, $perms, Path::makeRelative($item, $START_DIR)) . PHP_EOL;
- }
+ try {
+ $filesystem->chmod($item, octdec($perms), 0000, TRUE);
+ $output->writeln($perms . ' ' . $meta['icon'] . $label);
+ }
+ catch (IOException $exception) {
+ $output->writeln('' . $perms . ' ' . $meta['icon'] . $label . '');
+ $output->writeln('' . $exception->getMessage() . '');
+ $failures[] = $exception->getMessage() . PHP_EOL;
+// $failures[] = sprintf('Failed to set %s 😞 %s', $perms, Path::makeRelative($item, $START_DIR)) . PHP_EOL;
}
}
}
diff --git a/composer.json b/composer.json
old mode 100644
new mode 100755
diff --git a/json_schema/config.schema.json b/json_schema/config.schema.json
old mode 100644
new mode 100755
diff --git a/knowledge/.gitignore b/knowledge/.gitignore
old mode 100644
new mode 100755
diff --git a/knowledge/book.php b/knowledge/book.php
old mode 100644
new mode 100755
diff --git a/knowledge/book.yml b/knowledge/book.yml
old mode 100644
new mode 100755
diff --git a/knowledge/bookbinder.yml b/knowledge/bookbinder.yml
old mode 100644
new mode 100755
diff --git a/knowledge/chapters.yml b/knowledge/chapters.yml
old mode 100644
new mode 100755
diff --git a/knowledge/composer.json b/knowledge/composer.json
old mode 100644
new mode 100755
diff --git a/knowledge/index.yml b/knowledge/index.yml
old mode 100644
new mode 100755
diff --git a/knowledge/pages/general/CHANGELOG.md b/knowledge/pages/general/CHANGELOG.md
old mode 100644
new mode 100755
diff --git a/knowledge/pages/general/README.md b/knowledge/pages/general/README.md
old mode 100644
new mode 100755
index e525670..da71b45
--- a/knowledge/pages/general/README.md
+++ b/knowledge/pages/general/README.md
@@ -3,26 +3,29 @@ id: readme
tags: ''
-->
+# Easy Perms
+
Add this to a project to be able to easily manage file permissions.
-The files in a web app are likely to require writeable and executable permissions on some files, but not most. This tool allows you to set a baseline and then be only as permissive as necessary. The management is simply to add paths or globs to a YAML or JSON file and then run the script.
+The files in a web app are likely to require writeable and/or executable permissions on some files, but not most. It's time-consuming and may be confusing to keep these in order. This tool allows you to set a baseline and then be only as permissive as necessary. The management is simply to add paths or globs to a YAML or JSON file and then run the script.
**This project does not handle ownership of files, by design.** It assumes proper owner and group on all files, and merely sets the octal permissions.
## Configuration
* Both YAML and JSON is supported.
-* See _json_schema/config.schema.json_ for details of the configuration.
+* See _json\_schema/config.schema.json_ for details of the configuration.
+* Notice globs are supported. So are `/**/` doubles.
+* **Directories are ALWAYS recursive.** Don't be confused because, you will not see the recursive files in the output.
+* Also, the same and same number of files are handled by `../..` and `../../*`; however with the second example you will see the glob-matched filenames in the output, so it may be more desirable to use that format.
_./bin/config/perms.yml_
```yaml
default:
- - ../..
- ../../*
writeable:
- ../../web/sites/*/files
- - ../../web/sites/*/files/*
executable:
- ../../vendor/bin/*
```
@@ -51,7 +54,7 @@ Apply permissions like this:
## What Are the Permission Values?
* See `\AKlump\ProjectPermissions\DefaultFilePermissions` and `\AKlump\ProjectPermissions\DefaultDirectoryPermissions` for default values.
-* To override these values add something like the following to your configuration file:
+* To override these values add any or all of following to your configuration file:
```yaml
file_permissions:
@@ -63,3 +66,7 @@ directory_permissions:
writeable: '0770'
executable: '0750'
```
+
+## Troubleshooting
+
+This tool may reveal invalid symlinks, which you will see in the error output at the end, and should be deleted to avoid further errors.
diff --git a/knowledge/variables.yml b/knowledge/variables.yml
old mode 100644
new mode 100755
diff --git a/src/DefaultDirectoryPermissions.php b/src/DefaultDirectoryPermissions.php
old mode 100644
new mode 100755
diff --git a/src/DefaultFilePermissions.php b/src/DefaultFilePermissions.php
old mode 100644
new mode 100755
diff --git a/src/LoadConfig.php b/src/LoadConfig.php
old mode 100644
new mode 100755
index 93a109a..5044269
--- a/src/LoadConfig.php
+++ b/src/LoadConfig.php
@@ -62,6 +62,15 @@ private function ensureDefaults(array $config): array {
$config[$type] = [];
}
$config[$type] += $perms->jsonSerialize();
+
+ // Ensure we have octal strings as values.
+ $config[$type] = array_map(function ($value) {
+ if (is_int($value)) {
+ return '0' . decoct($value);
+ }
+
+ return $value;
+ }, $config[$type]);
}
return $config;