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

Fix du parameters on macOS #74

Merged
merged 1 commit into from
May 20, 2020

Conversation

friederbluemle
Copy link
Contributor

@friederbluemle friederbluemle commented Apr 5, 2020

Fixes #70 by not using the unsupported -b flag on macOS. Instead, we use -k which is supported on both Linux and macOS. Since the reported value is already in kilobytes, we no longer have to convert it in npkill.

Also fixes #67 (same issue).


export class LinuxFilesService extends FileService {
constructor(private streamService: StreamService) {
super();
}

getFolderSize(path: string): Observable<{}> {
const du = spawn('du', ['-s', '-b', path]);
const du = isOSMacOS() ? spawn('du', ['-s', path]) : spawn('du', ['-s', '-b', path]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the default is to return blocks. So this won’t give the right number on macOS (the reason for the original change to -b). AFAIK the default block size is 512b.

My suggestion is to use -k (kilobytes), and skip the bytes to kB call for macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment @marcins! You mean use -k instead of -s on macOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, use -sk I guess, since we're just interested in the summary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcins, you were absolutely right, it did not give the correct number on macOS.

Actually, the solution was much easier than what I initially tried with isOSMacOS: We can use du -sk on both Linux and macOS. :)

@Caballerog Caballerog changed the base branch from master to develop April 5, 2020 19:12
@tonivj5
Copy link
Member

tonivj5 commented Apr 5, 2020

Thanks for the PR @friederbluemle, I appreciate your contribution 👏

However, it resolves #70 and #67, it produces other drawbacks related with the reported size saved (as I commented here), because it's a non "real size". If you check the sizes reported using -b and -k, they could differ up to 50% bigger. I'm okey with revert the use of -b, running in macOS is more important, but we should look for how to resolve the source problem.

With nothing more to add, LGTM 👍

@tonivj5
Copy link
Member

tonivj5 commented Apr 5, 2020

I think @zaldih (and @NyaGarcia?) should comment here about this because he was who found the bug 👀

@friederbluemle
Copy link
Contributor Author

Thanks for your comment @tonivj5 - Definitely agree with you that this might not be the final fix. If you have a suggestion on how to address it in this PR please let me know. Otherwise we can merge it and you can submit a follow-up PR?

This PR is just the bare minimum to fix the current issue on macOS (i.e. npkill not working at all).

I did check your comment about the sizing problem, and tried to reproduce it locally. Could you explain a bit more how exactly the reported size deviates from the "real size"? Thank you!

@tonivj5
Copy link
Member

tonivj5 commented Apr 6, 2020

Otherwise we can merge it and you can submit a follow-up PR?

Totally I agree with you

I did check your comment about the sizing problem, and tried to reproduce it locally. Could you explain a bit more how exactly the reported size deviates from the "real size"?

I think this article is going to explain it better than me. However, both sizes are "real", we have noticed that -b gets us a huge difference calculating the freed space of node_modules. And seeing the size reported from other file managers (Dolphin from my side), they report the space as du -b does.

I'm not completely sure, but I remember @zaldih had or saw an issue for that reason.

Maybe, we was doing the wrong way here, but I'm not very confident now 🙊

@friederbluemle
Copy link
Contributor Author

@tonivj5 - Okay, that makes sense.

So it sounds like -b will give the exact (or apparent) size of the data on disk, while -k will provide the occupied disk space in kilobytes?

It sounds to me the "exact" byte size (-b) is less interesting here, and we really should be using -k anyway (even if it may be slightly off the "real" occupied space). That's still much better than using -b which could be orders of magnitude off.

For example: Consider a directory with 1,000 files in it. Each one only contains a single character (1 Byte). What should a tool report if asked for the size of the directory? 1,000 Bytes? Not really... The disk space the directory occupies is much higher: With a disk block size of 4096 Bytes it is around 4 Megabytes!

Since node_modules/ typically contains many small files, the occupied size is higher than the "real" size. And since npkill is about telling someone how much space will be saved, it will be much more accurate to use the "occupied" size instead of "real" size.

@friederbluemle
Copy link
Contributor Author

Btw, I just rebased my PR head branch on top of develop - I've noticed this repo is using two "main" branches (develop and master), and it appears PRs should be submitted not against the default branch (master). This is slightly confusing and maybe should be pointed out explicitly in the README.md.
Or even better - Remove one branch (ideally the non-default one, develop) and move to a single branch model (master). Since the repo is already using tags for releases there is no benefit in using more than one main branch. It creates unnecessary complexity and increases branch "spaghetti" ;)

git log --graph --oneline

@friederbluemle
Copy link
Contributor Author

Btw, if you want to check the block size of your disk on macOS:

diskutil info / | grep "Block Size"

And on Linux (replace <device> with the name of your device):

blockdev --getbsz /dev/<device>

@Caballerog Caballerog self-requested a review April 7, 2020 10:58
@tonivj5
Copy link
Member

tonivj5 commented Apr 12, 2020

Since node_modules/ typically contains many small files, the occupied size is higher than the "real" size. And since npkill is about telling someone how much space will be saved, it will be much more accurate to use the "occupied" size instead of "real" size.

Yeah, I agree 👍

@zaldih has the last word about this, awaiting for his review 👀

@NyaGarcia
Copy link
Member

Hi folks, sorry for the delay in answering 😅
So I read the discussion, and I can definitely agree that, even though this might not be the final fix, it's better to have a half working solution than none at all. So I'll accept this for the time being, and I'll try to find a better solution. Thank you all for helping out 😺

@NyaGarcia NyaGarcia merged commit d3b2005 into voidcosmos:develop May 20, 2020
@friederbluemle friederbluemle deleted the fix-du-macos branch May 20, 2020 19:58
@tonivj5 tonivj5 mentioned this pull request Jul 28, 2020
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

Successfully merging this pull request may close these issues.

No directories found Folder sizes always blank
4 participants