leo-arch / clifm

The shell-like, command line terminal file manager: simple, fast, extensible, and lightweight as hell.
https://github.com/leo-arch/clifm/wiki
GNU General Public License v2.0
1.35k stars 39 forks source link

pp on a symbolic link to a directory shows always 0 bytes #226

Closed muellerto closed 1 year ago

muellerto commented 1 year ago

Describe the bug If you have a symbolic link to a directory clifm's file list shows that there's content. If the user runs pp on that entry the pp output says always 0 bytes, as if the directory would be empty.

Expected behavior I would think it would be a good idea to handle a symbolic link to a directory exactly like the directory itself. pp should sum up the sizes of the files contained in the directory. p could say 0 bytes.

Desktop

Additional context I know du requires -D for symbolic links and does then sum up but the caller must not use -D for real directories, this leads to a totally different output. But here the type of the item is already known, you can call du in every case correctly.

leo-arch commented 1 year ago

Hi @muellerto. Thanks for reporting, as always.

The thing is: in previous versions, both the p and pp commands always returned information about the dereferenced symlink, providing no way to get info about the link itself. So, I decided to follow some standard practices (mostly ls(1) and stat(1)): in case of symlinks to directories they give info about the symlink if the name passed doesn't end with a slash. Otherwise, they provide information about the target directory.

However, as you noticed yourself, this wasn't enough for clifm:

  1. The procedure outlined above only applies to directories. But what about symlinks to non-directory files?
  2. The pp command is mainly intended to work with directories, so that printing full directory information (mostly recursive size) just makes sense.

So, after thinking about it for a while, I came out with this solution:

  1. p never dereferences symlinks.
  2. pp always dereferences symlinks, and, in case of directories, it prints the full directory size.

In this way, pp works as before, with the added feature of dereferencing symlinks. If you rather need information about the link itself, just use p. I think this new behavior is more consistent and predictable.

muellerto commented 1 year ago

Great! Have it already.

Another solution could have been that the pp output contains both the original line from p related to the link itself and an additional line below related to the contents.

I've seen on Linux a link itself has indeed always a size of some few bytes, on Windows it's just 0.

Thanks a lot for this. I think it's transparent and explainable now.