Skip to content

Refactor of paths detection #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2016
Merged

Conversation

vonalbert
Copy link
Contributor

Hello everyone, I'm aware you're not accepting contributions from the public, but i want to share my 5 cents, and you're free to reject these changes. Following there is a list of the changes and the motivations for each one:

  1. Maybe it's better to ensure the current directory is always the FC path
  2. is_dir checks both relative and absolute paths so we only need to check if the $system_path and $application_folder are valid directories and then save the constant using realpath
  3. realpath(DIR) is redundant because as far as i know DIR === realpath(DIR)
  4. I'm removing the check of application folder inside the system folder because it's an unnecessary operation, since it could be done setting the $application_folder variable to 'system/application';
  5. There's no need to replace the directory separators before apply a realpath because the substitution is provided by realpath itself (maybe is it there for the realpath's caching features?)

Hello everyone, I'm aware you're not accepting contributions from the public, but i want to share my 5 cents, and you're free to reject these changes. Following there is a list of the changes and the motivations for each one:
1) Maybe it's better to ensure the current directory is always the FC path
2) is_dir checks both relative and absolute paths so we only need to check if the $system_path and $application_folder are valid directories and then save the constant using realpath
3) realpath(__DIR__) is redundant because as far as i know __DIR__ === realpath(__DIR__)
4) I'm removing the check of application folder inside the system folder because it's an unnecessary operation, since it could be done setting the $application_folder variable to 'system/application';
5) There's no need to replace the directory separators before apply a realpath because the substitution is provided by realpath itself (maybe is it there for the realpath's caching features?)
@lonnieezell
Copy link
Member

First off, thanks. I hadn't taken the time to look through this logic, yet, but had largely just copied it from CI3. Looks like there is definitely some logic in here that's not needed, like the application directory inside of system folder, which can be simplified or removed. Some of them, though, I get the feeling there was a reason at one time, but some of those issues might have been resolved in newer versions of PHP.

  1. I can't think of a problem with this one.
  2. I'm trying to think of a reason why this logic would have been in place, and can't come up with it, since realpath ensures that all directories have executable permissions. Unless it has something to do with open_basedir restrictions returning false during a realpath, when it's still perfectly executable?
  3. Looking at PHP docs, I think this might be incorrect. Docs say the DIR is identical to dirname(FILE). Looking at dirname, then, we see this line: "dirname() operates naively on the input string, and is not aware of the actual filesystem". So we need to keep this check, it sounds like.
  4. Absolutely agree with this. Appears this was here specifically for ExpressionEngine support in days gone by.
  5. I'm not 100% on this one. All of the examples that I've seen regarding Windows has it being substituted as we currently do. Whether or not that's still required in PHP7, I don't know. This warrants more research.

@narfbg Do you have any idea about the validity or necessity of these, especially 2 and 5?

@narfbg
Copy link
Collaborator

narfbg commented Mar 29, 2016

  1. If realpath() was flawless, these checks wouldn't exist ... obviously somebody had a problem with it. Don't know what exactly.
  2. CI3 doesn't have that.

@lonnieezell
Copy link
Member

Are your 1 and 2 supposed to match up with the above numbering system, or just general points?

If they are supposed to match up, then this is what I was taking 2 to refer to.

@narfbg
Copy link
Collaborator

narfbg commented Mar 29, 2016

Huh ... that's Markdown's fault. I wrote 2 and 5 respectively.

@lonnieezell
Copy link
Member

Ah, that makes more sense then. And 5 has been a recent change, IIRC. This code came directly from CI3 originally. Good to know we can clean that up a little, though.

@narfbg
Copy link
Collaborator

narfbg commented Mar 29, 2016

Not directly ... you've made some modifications to it and 5 is part of them. :)

@lonnieezell
Copy link
Member

Oh, that's right. Realpath wasn't used there and I had a brainfart one night thinking that might help improve the realpath caching of files so scattered a few likely useless realpath's around. :)

@vonalbert
Copy link
Contributor Author

Oh didn't know 5 was already fixed in the official repo.

So for 3, unless i'm missing some edge cases i'm not aware of, DIR should always exists. Anyway no probs for me in leaving it at his place. I'm referring to
define('FCPATH', realpath(__DIR__).DIRECTORY_SEPARATOR);
Anyway I found this stackoverflow link on this subject
http://stackoverflow.com/questions/9415940/is-realpath-redundant-in-absolutepath-realpath-dir-is-dir-always

For 2 I'll research more this evening if you feel it requires modifications.

Perform a realpath check just before any is_dir to ensure the application and system path have executable permissions
}
else
// Are the system and application paths correct?
if ( ! realpath($system_path) OR ! is_dir($system_path))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this to ensure $system_path (and $application_folder below) have executable permissions

@lonnieezell
Copy link
Member

I'm going to go ahead and merge this for now. Firing up Parallels to be able to check it out under Windows, also. This is something we'll need to keep an eye on, but I do like the simplifications.

Thanks.

@lonnieezell lonnieezell merged commit b9475d5 into codeigniter4:develop Mar 30, 2016
@vonalbert vonalbert deleted the patch-1 branch March 30, 2016 07:11
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