dotfiles icon indicating copy to clipboard operation
dotfiles copied to clipboard

Replace `wc` by `stat` in `gz`

Open Rudxain opened this issue 1 year ago • 9 comments

fixes #1042 . Only did 1 unit test, I haven't tested the whole fn

Rudxain avatar Mar 16 '23 00:03 Rudxain

Thanks to your issue (#1042), I just found out that stat -c is GNU, but that macOS/FreeBSD use stat -f. Also, their format flags don’t match (!) but these both return file size:

# GNU
stat -c '%s' file

# macOS/FreeBSD
stat -f '%z' file

But a heads up, you should add the -L argument (same on both platforms) so that even calling a symlink returns the results you want.

LucasLarson avatar Mar 16 '23 01:03 LucasLarson

stat -c is GNU, but that macOS/FreeBSD use stat -f. Also, their format flags don’t match

Thank you for the info! I'll try to make it cross-platform

But a heads up, you should add the -L argument (same on both platforms) so that even calling a symlink returns the results you want.

That's also useful. I forgot about symlinks

Rudxain avatar Mar 16 '23 22:03 Rudxain

I'm getting an error

stat -cL '%s' -- .bash_history
# prints this...
# stat: cannot statx '%s': No such file or directory

@LucasLarson what am I doing wrong?

Rudxain avatar Mar 16 '23 23:03 Rudxain

You want this:

stat -Lc '%s' -- .bash_history

because %s is an argument of the -c option.

LucasLarson avatar Mar 16 '23 23:03 LucasLarson

because %s is an argument of the -c option.

I forgot that flag-ordering matters in rare cases.

Fixing now!

Rudxain avatar Mar 17 '23 03:03 Rudxain

Wait, I just noticed targz uses both stats, without a uname -s-based condition. I'll use that "hack" (not really a hack, because it's the simplest most reliable way known)

Rudxain avatar Mar 17 '23 03:03 Rudxain

You may want to keep the -L option dropped in 72303304b8

LucasLarson avatar Mar 17 '23 12:03 LucasLarson

You may want to keep the -L option dropped in 72303304b8

Silly me 😅. I forgot the L when copy-pasting

Rudxain avatar Mar 17 '23 19:03 Rudxain

Now it's ready (for real, haha)

I've been busy, and thinking of many things yesterday. It seems my cognitive load was higher than I expected. I apologize (to everyone) for the little mistakes

Rudxain avatar Mar 17 '23 19:03 Rudxain