nodejs-disks
nodejs-disks copied to clipboard
If mount point has a space, the whole mount point isn't parsed correctly
It looks like the mount point splits the string by space and returns the first part, for example, if the mount point is NO NAME
then the mount point of that disk would be NO
, example output below:
{
used: '2.34 MB',
available: '1.84 GB',
mountpoint: '/Volumes/NO',
freePer: '100',
usedPer: '0',
total: '1.84 GB',
drive: '/dev/disk2s1'
}
Volumes available
luke:/ $ ls -lah /Volumes
drwxrwxr-x 74 root admin 2.5K 12 Oct 10:34 Dev
drwxrwxrwx@ 1 luke 1451579101 16K 31 Dec 1979 NO NAME
lrwxr-xr-x 1 root admin 1B 5 Oct 14:08 OSX -> /
I found a potential solution to this issue. When parsing for the mountpoint, instead of using awk '{print $6}'
, which splits on spaces, use awk 'BEGIN {FS="[ ]*[0-9]+%?[ ]+"}; {print $6}'
which uses a regular expression to split on the size column entries.
When I have some time I'll submit a pull request for this.
Solution modified from this StackOverflow answer.
Thanks @Ferdaszewski - I'll test that solution some time this week.
By the way, this was never fixed. I already fixed this on my local system, came here to point this out, turns out someone already did 3 years ago haha. It would be great if you guys fix this so that we can use official unmodified modules without too many issues in case someone replaces all the modules installed
I would like to add that I just tried @Ferdaszewski 's code and it caused issues with my "/" partition. Didn't really bother to investigate since it's part of a larger piece of code, but the one I have that has been working so far for me is this:
'df
| grep ' + drive + ' | awk '{for (i=1;i<=5;i++){$i=""};print}''
Edit: Github comments doesn't like escape characters, so removed them. Just add them bak ofcause