Talk:Walk a directory/Recursively: Difference between revisions
Content added Content deleted
Line 32: | Line 32: | ||
::::will say it is a directory, and you can do globbing on it just like normal dirs. You'd have to specifically remember to check if it's a symlink. --[[User:Ledrug|Ledrug]] 20:53, 13 June 2011 (UTC) |
::::will say it is a directory, and you can do globbing on it just like normal dirs. You'd have to specifically remember to check if it's a symlink. --[[User:Ledrug|Ledrug]] 20:53, 13 June 2011 (UTC) |
||
:::::Ok, yes, bash is very inconsistent about how it handles symlinks. I remember talking with the bash maintainer about this, a number of years ago, and felt unsatisfied afterwards. In particular, <code>cd ../example</code> can fail, while <code>cd -P .; cd ../example</code> can succeed, because bash implements its own rules for about what directories are in the context of symbolic links, which conflicts with that of the underlying operating system. But that's a bash issue -- I do not know of any other language which suffers from that design. (And bash can rely on <code>find</code> or <code>ls</code> which implement sane treatment of symbolic links.) --[[User:Rdm|Rdm]] 23:37, 13 June 2011 (UTC) |
:::::Ok, yes, bash is very inconsistent about how it handles symlinks. I remember talking with the bash maintainer about this, a number of years ago, and felt unsatisfied afterwards. In particular, <code>cd ../example</code> can fail, while <code>cd -P .; cd ../example</code> can succeed, because bash implements its own rules for about what directories are in the context of symbolic links, which conflicts with that of the underlying operating system. But that's a bash issue -- I do not know of any other language which suffers from that design. (And bash can rely on <code>find</code> or <code>ls</code> which implement sane treatment of symbolic links.) --[[User:Rdm|Rdm]] 23:37, 13 June 2011 (UTC) |
||
::::::Eh, not really a bash specific problem. E.g. <pre>perl -e 'print "is a dir\n" if -d "/some/symlink/dir"</pre> or zsh <pre>if [[ -d /some/symlink/dir ]]; then echo "is a dir"; fi</pre> basically <lang C>#include <stdio.h> |
|||
#include <sys/types.h> |
|||
#include <dirent.h> |
|||
int main() { |
|||
DIR * x = opendir("/symlink/dir"); |
|||
if (x) { |
|||
printf("open ok\n"); |
|||
closedir(x); |
|||
} else { |
|||
printf("open not ok\n"); |
|||
} |
|||
return 0; |
|||
} |
|||
</lang> will succeed on openning a symlinked dir (it makes sense), and that's the thing one needs to check for. |