Giter Club home page Giter Club logo

Comments (16)

marcins avatar marcins commented on May 18, 2024 3

I tracked down the issue to this line:

const du = spawn('du', ['-s', '-b', path]);

It looks like this was changed recently in cdab878.

It appears the -b option used here does not exist on macOS. -b returns the output in bytes, and displays the "apparent size". The closest I could get on macOS is to use -k, but this doesn't do the "apparent size part" - not sure if that's super important though. -k should work on both Linux and macOS.

The other issue though is that the du command throwing an error is getting swallowed somewhere.

from npkill.

marcins avatar marcins commented on May 18, 2024 3

@zaldih just removing -b will give you the size in blocks though.

As I suggested in my comment - the best cross-platform approach might be to use -k to get the output in kilobytes (I assume linux has that!) - you'll lose the --apparent-size part though.

Alternatively you might need to detect macOS and just do the -k thing on Mac but keep -b for Linux.

from npkill.

marcins avatar marcins commented on May 18, 2024 2

@tonivj5 macOS doesn't have the. --block-size or --apparent-size options in du.

The man page says du reads a BLOCKSIZE env var, but when I try that with BLOCKSIZE=1 then you get an error that du: minimum blocksize is 512.

Since I couldn't find an up-to-date online man page, I copy and pasted the man du into a gist (this is for macOS 10.14.6 Mojave - haven't upgraded to Catalina yet): https://gist.github.com/marcins/2cb75a7b51166f99402166bc13d63d26

from npkill.

friederbluemle avatar friederbluemle commented on May 18, 2024 2

@tonivj5 - Sure!

So for macOS (BSD?) there is no --help, all it outputs is this:

$ du --help
du: illegal option -- -
usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m | -g] [-x] [-I mask] [file ...]

du --help for GNU coreutils:

(click to expand)

$ du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of the set of FILEs, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -0, --null            end each output line with NUL, not newline
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in ('sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -b, --bytes           equivalent to '--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --files0-from=F   summarize disk usage of the
                          NUL-terminated file names specified in file F;
                          if F is -, then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --inodes          list inode usage information instead of block usage
  -k                    like --block-size=1K
  -L, --dereference     dereference all symbolic links
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -S, --separate-dirs   for directories do not include size of subdirectories
      --si              like -h, but use powers of 1000 not 1024
  -s, --summarize       display only a total for each argument
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,
                          or entries greater than SIZE if negative
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using STYLE, which can be:
                            full-iso, long-iso, iso, or +FORMAT;
                            FORMAT is interpreted like in 'date'
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -x, --one-file-system    skip directories on different file systems
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
Binary prefixes can be used, too: KiB=K, MiB=M, and so on.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Full documentation <https://www.gnu.org/software/coreutils/du>
or available locally via: info '(coreutils) du invocation'

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024 1

-b is a shortcut to --apparent-size --block-size=1.

-b, --bytes
              equivalent to '--apparent-size --block-size=1'

I suppose these options are available in macOS, @marcins can you test it if du -s --apparent-size --block-size=1 returns you a number?

from npkill.

zaldih avatar zaldih commented on May 18, 2024 1

A few minutes ago I managed to replicate the problem. It seems that the bug was introduced in the jump from version 0.6.x to 0.7.0 as discussed in some other issue and it only seems to affect Mac.

I noticed that when the search is over, if I press down arrow, the hidden directories suddenly appear.
Could you check if this works for you?
edit: okay i have seen it worked on #67 ,and it seems to be related

I'm investigating the exact cause why that occurs.

from npkill.

zaldih avatar zaldih commented on May 18, 2024 1

@marcins You're right!!! You have just found the problem!
By removing the -b parameter, everything seems to work as it should.

I am very confused. I also do not understand why on Mac it behaves that way.
We will continue investigating

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024 1

@marcins thanks for test it πŸ‘

--apparent-size get us the most accurate folder size. This param resolves some bugs with calculation of folder size, because node_modules are composed of a lot of small files, and using the block size give us a bigger folder size (maybe even GBs of difference respect its real size).

That's a problem in du command itself... Maybe should search another way to calculate the node_modules size πŸ˜†

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024 1

@marcins could you copy paste in a gist the output of du --help? The docs of freebsd's du command shows a -A option similar to linux's --aparent-size. Maybe the man page is out of date...

from npkill.

friederbluemle avatar friederbluemle commented on May 18, 2024 1

Thanks all for investigating this issue! πŸ‘

@marcins - The du man page on macOS Catalina (10.15.4) is exactly the same as what you posted in your gist.

For reference, I created two gists with the man page of du here:

GNU coreutils 8.32

https://gist.github.com/friederbluemle/06e34f9401a9b3d90a780f2694df93e4

macOS 10.15.4 (19E266)

https://gist.github.com/friederbluemle/4fa8abe4d0653e0ccd26c5b22b717b70

Both files created using this command:

MANWIDTH=100 man du | col -bx > file.txt

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024 1

Hey, @friederbluemle could you create a gist with the output of du --help command? πŸ˜… To be sure that man pages are up to date with the du version installed...

Thanks πŸ‘πŸ‘

from npkill.

friederbluemle avatar friederbluemle commented on May 18, 2024 1

Opened a quick PR here with a fix: #74 - Please check πŸ‘

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024

So for macOS (BSD?) there is no --help, all it outputs is this

😱 Ok, that was enough πŸ˜†πŸ˜†

Hmm, I think we should investigate alternatives... πŸ€” Or if someone has some idea, it would be awesome

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024

As a possible idea, could use dust and its -s param as du replacement. It seems multi-platform

from npkill.

friederbluemle avatar friederbluemle commented on May 18, 2024

Personally, I am using dust and it is amazing, though I don't think we should make it a prerequisite for using npkill.
How about simple check of process.platform and running du with the correct parameters for the specific platform?

from npkill.

tonivj5 avatar tonivj5 commented on May 18, 2024

The problem with du is its lack of options in macOS. With --aparent-size we get real size of node_modules.

We could use -b in linux and other option in macOS, but it's going to produce other issues (that was the main issue because -b was added...). Me neither like to add a new dependency to resolve this.

But, yeah, we should do something πŸ˜†

from npkill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.