Skip to content

Commit

Permalink
Make directories recursive.
Browse files Browse the repository at this point in the history
  • Loading branch information
aklump committed Aug 26, 2023
1 parent 263862c commit e69e920
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 21 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .web_package/config
100644 → 100755
Empty file.
Empty file modified .web_package/hooks/bootstrap.php
100644 → 100755
Empty file.
Empty file modified .web_package/hooks/build/00_docs.sh
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
21 changes: 14 additions & 7 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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/*
```
Expand Down Expand Up @@ -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:
Expand All @@ -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.
20 changes: 11 additions & 9 deletions app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<error>' . $perms . ' ' . $meta['icon'] . $label . '</error>');
$output->writeln('<error>' . $exception->getMessage() . '</error>');
$failures[] = $exception->getMessage() . PHP_EOL;
// $failures[] = sprintf('Failed to set %s 😞 %s', $perms, Path::makeRelative($item, $START_DIR)) . PHP_EOL;
}
}
}
Expand Down
Empty file modified composer.json
100644 → 100755
Empty file.
Empty file modified json_schema/config.schema.json
100644 → 100755
Empty file.
Empty file modified knowledge/.gitignore
100644 → 100755
Empty file.
Empty file modified knowledge/book.php
100644 → 100755
Empty file.
Empty file modified knowledge/book.yml
100644 → 100755
Empty file.
Empty file modified knowledge/bookbinder.yml
100644 → 100755
Empty file.
Empty file modified knowledge/chapters.yml
100644 → 100755
Empty file.
Empty file modified knowledge/composer.json
100644 → 100755
Empty file.
Empty file modified knowledge/index.yml
100644 → 100755
Empty file.
Empty file modified knowledge/pages/general/CHANGELOG.md
100644 → 100755
Empty file.
17 changes: 12 additions & 5 deletions knowledge/pages/general/README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
```
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Empty file modified knowledge/variables.yml
100644 → 100755
Empty file.
Empty file modified src/DefaultDirectoryPermissions.php
100644 → 100755
Empty file.
Empty file modified src/DefaultFilePermissions.php
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions src/LoadConfig.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e69e920

Please sign in to comment.