shaun-h / nodejs-disks

Gets current disk information from Server hosting nodejs application
MIT License
22 stars 13 forks source link

On OS X (I suppose on linux too) returns wrong mount point if space used in drive's name #6

Open kloneets opened 8 years ago

kloneets commented 8 years ago

If, for example, my drive name would be some data, then nodejs-disks interprets mount point as /Volumes/some. This happens because mount point searching algorithm prints with awk 6th parameter. I suggest (it is my quick and dirty hack because I do not know awk) replacing this line 'df | grep ' + drive + ' | awk \'{print $6}\'' with this 'df | grep ' + drive + ' | grep -oh \' /.*\' | grep -oh \'/.*\''

kloneets commented 8 years ago

Ok, I looked closer to code and se, that trimming is performed afterwords with javascript, so, line could be just: 'df | grep ' + drive + ' | grep -oh \' /.*\''

jssuttles commented 8 years ago

Yeah. I've run into this as well. (Check out my fork.) I switched it with this: 'df -kl | grep ' + drive + ' | awk \'{ for (i = 9; i <= NF; i++) print $i}\' ORS=\' \'' Not the best because it assumes that the 9th is the beginning of the mount point. What if the first parameter has a space in it? What does yours do?

kloneets commented 8 years ago

Mine just finds row with drive and asumes that / will be last param with "/" (slash), which will be the mount point. So - it returns everything from this /. Extra space will be trimmed by javascript.

jssuttles commented 8 years ago

Does that get "/Volumes/some drive"?

kloneets commented 8 years ago

In my case it did :D

jssuttles commented 8 years ago

A case where that would fail is if the mount point folder has a trailing space ('/Volumes /some drive'). I think that's less possible than the first field having a space in it. So, it's a better solution than mine. Do you know if it's possible?

kloneets commented 8 years ago

Never saw such mountpoint naming, but users are geniuses and, if someone allows to do this, they will :D I just tested on my mac (el capitan) and my solution worked on flahsdrive called " My flash " (space before "My" and after "flash"). So - need to be tested on other platforms :)