Skip to content
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

Shows size power 2 (in MiB), but prints as if it is power 10 (MB) #807

Open
ValdikSS opened this issue Jan 18, 2023 · 2 comments
Open

Shows size power 2 (in MiB), but prints as if it is power 10 (MB) #807

ValdikSS opened this issue Jan 18, 2023 · 2 comments

Comments

@ValdikSS
Copy link

ValdikSS commented Jan 18, 2023

  • os: Fedora 37
  • lsd --version: lsd 0.22.0

lsd shows file size in non-si mebibytes/gibibytes (power of 2), while suggests it is megabytes/gigabytes (SI, power of 10).
In other words, the program should print 10 MiB instead of 10 MB.

Expected behavior

$ lsd -la openwrt-22.03.3-x86-generic-generic-squashfs-combined-efi.img
.rw-r--r--. valdikss valdikss 120 M**i**B Wed Jan 18 19:17:34 2023 openwrt-22.03.3-x86-generic-generic-squashfs-combined-efi.img

Actual behavior

$ lsd -la --size=bytes openwrt-22.03.3-x86-generic-generic-squashfs-combined-efi.img
.rw-r--r--. valdikss valdikss 126123520  Wed Jan 18 19:17:34 2023 openwrt-22.03.3-x86-generic-generic-squashfs-combined-efi.img

$ lsd -la openwrt-22.03.3-x86-generic-generic-squashfs-combined-efi.img
.rw-r--r--. valdikss valdikss 120 **MB** Wed Jan 18 19:17:34 2023 openwrt-22.03.3-x86-generic-generic-squashfs-combined-efi.img

126123520 bytes is 126 MB or 120 MiB.

@meain meain added kind/bug Something isn't working and removed kind/bug Something isn't working labels Jan 19, 2023
@meain
Copy link
Member

meain commented Jan 19, 2023

Looking at gnu ls, it looks like they also use 1024 by default and uses 1000 when --si flag is provided. That said, the way they round it off is different.

$ truncate -s 126123520 foo

$ lsd -l foo
.rw-rw-r-- 120M now foo

$ ls -lh foo
-rw-rw-r-- 1 meain meain 121M Jan 19 10:29 foo

$ ls -lh --si foo
-rw-rw-r-- 1 meain meain 127M Jan 19 10:29 foo

$ cargo run -- -l foo  # div by 1000
   Compiling lsd v0.23.1 (/home/meain/dev/src/lsd)
    Finished dev [unoptimized + debuginfo] target(s) in 2.27s
     Running `target/debug/lsd -l foo`
.rw-rw-r-- 126M 14 seconds ago foo

From the man page:

       -h, --human-readable
              with -l and -s, print sizes like 1K 234M 2G etc.

       --si   likewise, but use powers of 1000 not 1024

We should also consider supporting the --si flag from gnu ls when we change this behavior.

Adding some references:

@frankebel
Copy link

I saw a request #826.

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

No branches or pull requests

3 participants