Skip to content

Filesystem::write() accept NULL in $mode parameter#139

Merged
dg merged 7 commits into
nette:masterfrom
jkuchar:patch-1
Jun 12, 2017
Merged

Filesystem::write() accept NULL in $mode parameter#139
dg merged 7 commits into
nette:masterfrom
jkuchar:patch-1

Conversation

@jkuchar

@jkuchar jkuchar commented May 9, 2017

Copy link
Copy Markdown
Contributor
  • bug fix? yes
  • new feature? no
  • BC break? no (fixing unintended Nette 2.x BC break)

Code of function expects $mode to be NULL. If that happens it does not chmod it.

@dg

dg commented May 9, 2017

Copy link
Copy Markdown
Member

It breaks compatibility with PHP 7.0

@dg

dg commented May 17, 2017

Copy link
Copy Markdown
Member

Ping @jkuchar

Comment thread src/Utils/FileSystem.php Outdated

/**
* Writes a string to a file.
* @param $mode int|NULL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to write php doc here as you usually do not use @param with $variableName.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most importantly you switched parameter name with parameter type, the annotation should be @param int|NULL $mode

Comment thread src/Utils/FileSystem.php Outdated
public static function write(string $file, string $content, $mode = 0666)
{
assert($mode === NULL || is_int($mode));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually use assert when there is no possibility of declaring type using typehint (union types, ...) Do you like it or should it fail at line 144

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unnecessary to me.

@jkuchar

jkuchar commented Jun 6, 2017

Copy link
Copy Markdown
Contributor Author

@JanTvrdik thanks for review, updated

Comment thread src/Utils/FileSystem.php Outdated

/**
* Writes a string to a file.
* @param int|NULL $mode

@jkuchar jkuchar Jun 6, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look obvious what this parameter does... Is that creation mode or does it override current file mode?

Maybe add to docs something like:

  • Alters file mode to given value (does not matter if file already or will be created exists)

Shouldn't NULL be the default value? created follow up in #140 and PR #141

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be two spaces after @param to align with @return and @throws.

@jkuchar

jkuchar commented Jun 8, 2017

Copy link
Copy Markdown
Contributor Author

@JanTvrdik Should I squash this, have you finished review?

@jkuchar

jkuchar commented Jun 8, 2017

Copy link
Copy Markdown
Contributor Author

@JanTvrdik Added the same fix also for createDir() e5ecd37 Anything more that needs to be fixed?

@JanTvrdik

Copy link
Copy Markdown
Contributor

@jkuchar Hopefully not.

@dg

dg commented Jun 9, 2017

Copy link
Copy Markdown
Member

How differs mkdir($dir, 0777) from mkdir($dir, NULL)?

This reverts commit e5ecd37.
@jkuchar

jkuchar commented Jun 9, 2017

Copy link
Copy Markdown
Contributor Author

TL;DR: @dg you are right. NULL should be prohibited as it is evaluated to 0000 permission. Good catch! Interesting is that when mkdir is called with 0777 it is ignored and creates directory with default directory permissions. (is that somehow related to umask?)

I have performed the following test.

mkdir("testFromPHPNULL", NULL);
mkdir("testFromPHP0777", 0777);
exec("mkdir -m 0777 testFromBash0777");
exec("mkdir testFromBashDefault");

Tried this obscure situation with ACLs:

$ getfacl .                                 
# file: .
# owner: jkuchar1a
# group: domain^users
user::rwx
group::r-x                      #effective:---
mask::---
other::---
default:user::rwx
default:group::r-x              #effective:---
default:mask::---
default:other::---
$ ll
drwx------+  2 jkuchar1a domain^users 4096 čen  9 19:40 testFromBashDefault/
drwx------+  2 jkuchar1a domain^users 4096 čen  9 19:40 testFromBash0777/
d---------+  2 jkuchar1a domain^users 4096 čen  9 19:40 testFromPHPNULL/  <--- WRONG
drwx------+  2 jkuchar1a domain^users 4096 čen  9 19:40 testFromPHP0777/

Result permissions on testFromBashDefault and testFromPHP0777 are the same.

When no ACLs are used it behaves the same.

$ ll
drwxr-xr-x  2 jkuchar1a domain^users 4096 čen  9 19:46 ./
drwxr-xr-x 12 jkuchar1a domain^users 4096 čen  9 19:26 ../
drwxr-xr-x  2 jkuchar1a domain^users 4096 čen  9 19:50 testFromBashDefault/
drwxrwxrwx  2 jkuchar1a domain^users 4096 čen  9 19:50 testFromBash0777/ <--- WRONG
d---------  2 jkuchar1a domain^users 4096 čen  9 19:50 testFromPHPNULL/ <--- WRONG
drwxr-xr-x  2 jkuchar1a domain^users 4096 čen  9 19:50 testFromPHP0777/

@dg

dg commented Jun 12, 2017

Copy link
Copy Markdown
Member

Thanks

@dg dg merged commit c01d1d1 into nette:master Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants