sebhildebrandt / systeminformation

System Information Library for Node.JS
MIT License
2.72k stars 309 forks source link

The size obtained by diskLayout on MacOS is 1 #93

Closed Sextants closed 6 years ago

Sextants commented 6 years ago

Issue Type

Expected behavior

Actual behavior

Steps to reproduce the problem

-

-

Specifications

Problem and possible solution

In the 628 line of filesystem.js, the code is as follows: let size = parseInt(sizeStr.match(/(([^)]+))/)[1].replace(/./g, '')); I think the change of a sentence to a comma can be solved

sebhildebrandt commented 6 years ago

Hi, sorry for the mess ... seems that I made a mistake here. And thank you for your detailed description. This will help to solve it ... small remark: as the output seems to be dependent on the language (size value sometimes with „.“ sometimes with „,“), I will only need to replace both. Anyway, I will have to cleanup some smaller things in this part of the code and will provide a fix this weekend.

sebhildebrandt commented 6 years ago

Should work now - new version 3.33.8 just published. Can you test it on your side? Sorry once again.

Sextants commented 6 years ago

Thank you for your prompt reply

xferra commented 3 years ago

Hello, the same issue with systeminformation 5.8.9

MacBook Air, macOS BigSur 11.2.3

system_profiler:

    Apple SSD Controller:

        APPLE SSD AP0128M:

          Capacity: 121,33 GB (121 332 826 112 bytes)
          TRIM Support: Yes
          Model: APPLE SSD AP0128M
          Revision: 1161.80.
          Link Width: x4
          Link Speed: 8.0 GT/s
          Detachable Drive: No
          BSD Name: disk0
          Partition Map Type: GPT (GUID Partition Table)
          Removable Media: No
          S.M.A.R.T. status: Verified
          Volumes:
            EFI:
              Capacity: 314,6 MB (314 572 800 bytes)
              File System: MS-DOS FAT32
              BSD Name: disk0s1
              Content: EFI
              Volume UUID: E783267B-A4C3-3556-B751-DBED770EB996
            disk0s2:
              Capacity: 121,02 GB (121 018 208 256 bytes)
              BSD Name: disk0s2
              Content: Apple_APFS

Code:

const disk = await si.diskLayout();
console.log(disk);

Output:

[
  {
    device: 'disk0',
    type: 'NVMe',
    name: 'APPLE SSD AP0128M',
    vendor: 'Apple',
    size: 121,
    bytesPerSector: null,
    totalCylinders: null,
    totalHeads: null,
    totalSectors: null,
    totalTracks: null,
    tracksPerCylinder: null,
    sectorsPerTrack: null,
    firmwareRevision: '1161.80.',
    serialNum: '***',
    interfaceType: 'PCIe x4',
    smartStatus: 'Ok',
    temperature: null
  }
]

As you can see size is returned in GB.

sebhildebrandt commented 3 years ago

@xferra my fault ... sorry. Next npm version will have a corrected version. As I am waiting for one other commit to be testet, the next publishing will take 1-2 days ...

sebhildebrandt commented 3 years ago

@xferra Version 5.9.0 just published. Should fix this problem.

xferra commented 3 years ago

@sebhildebrandt Much appreciated for such a quick update! Unfortunately, I could not confirm that it works as expected in V. 5.9.0.:

Here: https://github.com/sebhildebrandt/systeminformation/blob/master/lib/filesystem.js#L1040

Screenshot 2021-09-15 at 14 14 36
sizeStr == "121,33 GB (121 332 826 112 bytes)"
sizeValue == 121

Would you like me to create a PR or you could kindly fix it?

sebhildebrandt commented 3 years ago

@xferra ... hmmmm

If I do the following in node:

sizeStr = '121,33 GB (121 332 826 112 bytes)'
console.log(parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '').replace(/ /g, '')))

(last line is currently what happens in line 1040)

then I get 121332826112 ... (not just 121)

I am a little irritated, why this does not the same on your machine...

What if you replace line 1040 with

                    sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '').replace(/ /g, ''));

(means replacing ALL whitespaces with empty string)

Will it work then??

xferra commented 3 years ago

@sebhildebrandt

It works when I test it in a nodejs console, but not while debugging, heh. Then I've checked:

sizeStr.match(/\(([^)]+)\)/)[1].charCodeAt(3) === 160

So, the proposed solution is:

sizeValue = parseInt(sizeStr.match(/\(([^)]+)\)/)[1].replace(/\./g, '').replace(/,/g, '').replace(/\s/g, ''))
sebhildebrandt commented 3 years ago

@xferra thank you!!! Exactly what I expected ;-) So I hope new (just published) version 5.9.1 fixes this ;-)