amphp / file

An abstraction layer and non-blocking file access solution that keeps your application responsive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How should isfile and isdir work with symlink?

enumag opened this issue · comments

Current version of amphp is possibly inconsistent:

File\isfile('symlink-to-file') - true or false? (currently false)
File\isdir('symlink-to-directory') - true or false? (currently true - note that it doesn't resolve the link, it returns true as a sideeffect of bad behavior described below)

Note that I'm adding a new File\islink() function to detect symlinks.

For comparison PHP's is_dir returns true for symlink to directory according to docs.

is_file doesn't say but from my testing seems to resolve symlink too.

Another note is that currently isfile and isdir return the exact oposite value for an existing file. This may not be correct since it can be neither. For instance PHP's is_file and is_dir both return false for a FIFO.

Also note that if we decide to resolve symlinks for isfile and isdir then we need to do so in a while loop and remember all visited nodes to detect symlink loops.

Resolving symlinks seems like the proper thing to do, no? Regarding isLink, shouldn't it rather be isSymlink then?

looks like stat is resolving links internally so I guess I was doing something wrong.