Merge file size fields correctly on Windows (#19141)

* Merge file size fields correctly on Windows

Merge file size fields correctly on Windows

- Merge the two 32-bit file size fields from `BY_HANDLE_FILE_INFORMATION` correctly in `rawToFormalFileInfo`.
- Fixes #19135

* Update os.nim
This commit is contained in:
Clay Sweetser
2021-11-12 22:51:43 -05:00
committed by GitHub
parent c6fc3b2eae
commit 0a1049881e

View File

@@ -3255,7 +3255,11 @@ template rawToFormalFileInfo(rawInfo, path, formalInfo): untyped =
## 'rawInfo' is either a 'BY_HANDLE_FILE_INFORMATION' structure on Windows,
## or a 'Stat' structure on posix
when defined(windows):
template merge(a, b): untyped = a or (b shl 32)
template merge(a, b): untyped =
int64(
(uint64(cast[uint32](a))) or
(uint64(cast[uint32](b)) shl 32)
)
formalInfo.id.device = rawInfo.dwVolumeSerialNumber
formalInfo.id.file = merge(rawInfo.nFileIndexLow, rawInfo.nFileIndexHigh)
formalInfo.size = merge(rawInfo.nFileSizeLow, rawInfo.nFileSizeHigh)