lawlist · 2022-08-22 02:34
I am able to test the following issue on Emacs versions 25 to 27. Due to the tramp connection crashing the entire Emacs instance for me on Emacs 28 and 29 using El Capitan on my mac, I don't know if this particular behavior with `directory-files-and-attibutes` still exists. Before opening the proverbial "Pandora's Box" by submitting a formal bug report, is anyone able to confirm whether Emacs 29 currently behaves the same and (if known) why that is the case? [It is a Pandora's Box because I would potentially be assisting in debugging the crashes, before getting to the underlying issue.]
**Step #1**: Establish a remote Tramp session over `ssh`.
**Step #2**: Call `directory-files-and-attributes` using the following optional arguments:
`(directory-files-and-attributes "/ssh:user@01.23.456.789:/home3/lawlist" t nil t nil)`
**Step #3**: The return value *includes* both the starting directory, and the *parent* of the starting directory. [FYI: If there are lots of files/folders, the default settings of Emacs will truncate the list that gets returned ... so, either increase the print length or use something like `(message "%s" ....)` to avoid truncation.]
`/ssh:user@01.23.456.789:/home3`
`/ssh:user@01.23.456.789:/home3/lawlist`
**EXPECTED BEHAVIOR**: Do not return the starting directory, and do not return the parent directory of the starting directory.
IWant2rideMyBike · 2022-08-22 19:45
On most unixoid systems a normal directory contains the entries \`.\` and \`..\` which stand for the current and the parent directory (you can't see them in many programs by default because names starting with a dot count as hidden files and directories). Because you request full paths (instead of a relative ones) you get those as absolute paths.
Basically `directory-files-and-attributes` behaves like
ls -a | xargs realpath
but you want the behavior of
ls -A | xargs realpath
In this case it could be helpful to formulate a matching rule, but since Emac's regex engine doesn't provide a negative lookbehind (unlike e.g. PCRE), it seems to me that it is only possible to exclude all hidden files:
(directory-files-and-attributes "/ssh:user@01.23.456.789:/home3/lawlist" t "^[^.].*" t nil)
As to why - as far as I understand [https://github.com/emacs-mirror/emacs/blob/3af9e84ff59811734dcbb5d55e04e1fdb7051e77/src/dired.c#L316](https://github.com/emacs-mirror/emacs/blob/3af9e84ff59811734dcbb5d55e04e1fdb7051e77/src/dired.c#L316) ff. Emacs uses readdir to list the contents of the directory and this returns dirent structs including `.` and `..`.
lawlist · 2022-08-22 21:49
Thank you for the explanation -- greatly appreciated! Now that I understand "the why" and that this is not a bug, I can programmatically plan for and deal with this behavior.