From 7941c1038e651a310d4e116e03cd3d2f686e997f Mon Sep 17 00:00:00 2001 From: MrSmoer <66489839+MrSmoer@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:36:10 +0100 Subject: [PATCH 1/7] add attachTimestamp revert changes to gitignore --- lib/index.ts | 1 + lib/lsblk/index.ts | 19 ++++++++++++++ lib/lsblk/json.ts | 1 + lib/lsblk/pairs.ts | 1 + package-lock.json | 10 +++----- package.json | 6 ++--- src/darwin/list.mm | 11 +++++++- src/device-descriptor.cpp | 2 ++ src/drivelist.hpp | 1 + src/windows/list.cpp | 53 +++++++++++++++++++++++++++++++++++++++ target/npmlist.json | 1 + 11 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 target/npmlist.json diff --git a/lib/index.ts b/lib/index.ts index 9ecbf921..481e5bed 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -50,6 +50,7 @@ export interface Drive { raw: string; size: number | null; partitionTableType: 'mbr' | 'gpt' | null; + attachTimestamp: number | null; } const drivelistBindings = bindings('drivelist'); diff --git a/lib/lsblk/index.ts b/lib/lsblk/index.ts index 13e25243..c800b239 100644 --- a/lib/lsblk/index.ts +++ b/lib/lsblk/index.ts @@ -60,10 +60,29 @@ async function getDevicePaths(): Promise> { async function addDevicePaths(devices: Drive[]): Promise { const devicePaths = await getDevicePaths(); for (const device of devices) { + const path = devicePaths.get(device.device); device.devicePath = devicePaths.get(device.device) || null; + device.attachTimestamp= await getAttachTimestamp(path); } } +async function getAttachTimestamp(path: string | undefined): Promise { + const fs = require('fs'); + let time; + try { + const stats= await fs.promises.stat(path) + console.log(stats.mtime); + time = stats.mtime.getTime(); + } catch (err) { + time=0; + console.error(err); + } + + return time; + + +} + async function getOutput(command: string, ...args: string[]) { const { stdout } = await execFileAsync(command, args); return stdout; diff --git a/lib/lsblk/json.ts b/lib/lsblk/json.ts index 0820eb8f..1d454856 100644 --- a/lib/lsblk/json.ts +++ b/lib/lsblk/json.ts @@ -145,6 +145,7 @@ export function transform(data: LsblkJsonOutput): Drive[] { isUSB, isUAS: null, partitionTableType: getPartitionTableType(device.pttype), + attachTimestamp: null }; }, ); diff --git a/lib/lsblk/pairs.ts b/lib/lsblk/pairs.ts index 75af9fac..49d49b5e 100644 --- a/lib/lsblk/pairs.ts +++ b/lib/lsblk/pairs.ts @@ -182,6 +182,7 @@ export function parse(stdout: string): Drive[] { partitionTableType: getPartitionTableType( device.pttype as 'gpt' | 'dos' | undefined, ), + attachTimestamp: null }; }, ); diff --git a/package-lock.json b/package-lock.json index a97ed95d..acfb1653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,8 @@ "bindings": "^1.5.0", "debug": "^4.3.4", "node-addon-api": "^5.0.0", - "prebuild-install": "^7.1.1" + "prebuild-install": "^7.1.1", + "typescript": "^4.9.4" }, "devDependencies": { "@balena/lint": "^6.2.1", @@ -28,8 +29,7 @@ "node-gyp": "^9.3.1", "prebuild": "^11.0.4", "sinon": "^15.0.1", - "ts-node": "^10.9.1", - "typescript": "^4.9.4" + "ts-node": "^10.9.1" }, "engines": { "node": ">=16 < 19" @@ -7123,7 +7123,6 @@ "version": "4.9.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", - "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -13239,8 +13238,7 @@ "typescript": { "version": "4.9.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz", - "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==", - "dev": true + "integrity": "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==" }, "typical": { "version": "2.6.1", diff --git a/package.json b/package.json index ec127472..ba1c3784 100644 --- a/package.json +++ b/package.json @@ -51,14 +51,14 @@ "node-gyp": "^9.3.1", "prebuild": "^11.0.4", "sinon": "^15.0.1", - "ts-node": "^10.9.1", - "typescript": "^4.9.4" + "ts-node": "^10.9.1" }, "dependencies": { "bindings": "^1.5.0", "debug": "^4.3.4", "node-addon-api": "^5.0.0", - "prebuild-install": "^7.1.1" + "prebuild-install": "^7.1.1", + "typescript": "^4.9.4" }, "binary": { "napi_versions": [ diff --git a/src/darwin/list.mm b/src/darwin/list.mm index 0c35da3e..71883d68 100644 --- a/src/darwin/list.mm +++ b/src/darwin/list.mm @@ -102,6 +102,15 @@ DeviceDescriptor CreateDeviceDescriptorFromDiskDescription(std::string diskBsdNa device.isUAS = false; device.isUASNull = true; + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSString *path = [NSString stringWithUTF8String:("/dev/"+diskBsdName).c_str()]; + NSDate *dates = [[fileManager attributesOfItemAtPath:path error:NULL] fileModificationDate]; + //TODO path can be null and remove debug + NSLog(@"Unix time: %@", dates); + NSTimeInterval unixTime = [dates timeIntervalSince1970]; + NSLog(@"real Unix time: %f",unixTime); + device.attachTimestamp = unixTime; + return device; } @@ -146,7 +155,7 @@ DeviceDescriptor CreateDeviceDescriptorFromDiskDescription(std::string diskBsdNa mountedVolumeURLsIncludingResourceValuesForKeys:volumeKeys options:0 ]; - + for (NSURL *path in volumePaths) { DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, (__bridge CFURLRef)path); if (disk == nil) { diff --git a/src/device-descriptor.cpp b/src/device-descriptor.cpp index 26334415..4b9a2388 100644 --- a/src/device-descriptor.cpp +++ b/src/device-descriptor.cpp @@ -118,6 +118,8 @@ Napi::Object PackDriveDescriptor(Napi::Env env, : (Napi::Value)Boolean::New(env, instance->isUAS); object.Set(String::New(env, "isUAS"), isUAS); + object.Set(String::New(env, "attachTimestamp"), + Number::New(env, static_cast(instance->attachTimestamp))); return object; } diff --git a/src/drivelist.hpp b/src/drivelist.hpp index 2a731e66..30579737 100644 --- a/src/drivelist.hpp +++ b/src/drivelist.hpp @@ -40,6 +40,7 @@ struct DeviceDescriptor { std::string error; std::string partitionTableType; uint64_t size; + uint64_t attachTimestamp; uint32_t blockSize = 512; uint32_t logicalBlockSize = 512; std::vector mountpoints; diff --git a/src/windows/list.cpp b/src/windows/list.cpp index dfcc74f2..08570598 100644 --- a/src/windows/list.cpp +++ b/src/windows/list.cpp @@ -35,6 +35,21 @@ #include "../drivelist.hpp" #include "list.hpp" + +#define INITGUID +#ifdef DEFINE_DEVPROPKEY +#undef DEFINE_DEVPROPKEY +#endif +#ifdef INITGUID +#define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) EXTERN_C const DEVPROPKEY DECLSPEC_SELECTANY name = { { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }, pid } +#else +#define DEFINE_DEVPROPKEY(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8, pid) EXTERN_C const DEVPROPKEY name +#endif + +#ifndef DEVPKEY_Device_LastArrivalDate +DEFINE_DEVPROPKEY(DEVPKEY_Device_LastArrivalDate, 0x83da6326, 0x97a6, 0x4088, 0x94, 0x53, 0xa1, 0x92, 0x3f, 0x57, 0x3b, 0x29, 102); +#endif + namespace Drivelist { std::string WCharToUtf8String(const wchar_t* wstr) { @@ -657,6 +672,43 @@ bool GetDetailData(DeviceDescriptor* device, NULL, 0, &size, NULL); device->isReadOnly = !isWritable; + const int64_t UNIX_TIME_START= 0x019DB1DED53E8000; + const int64_t TICKS_PER_SECOND = 10000000; + DWORD requiredSize; + DEVPROPTYPE type; + WCHAR szBuffer[4096]; + BOOL hasArrivalDate = SetupDiGetDevicePropertyW(hDeviceInfo, &deviceInfoData, &DEVPKEY_Device_LastArrivalDate, + &type, (BYTE*)szBuffer, sizeof(FILETIME), &requiredSize, 0); + if (!hasArrivalDate) { + errorCode = GetLastError(); + device->error = "Couldn't SetupDiGetDeviceInterfaceDetailW: Error " + + std::to_string(errorCode); + result = false; + break; + + } + DEVPROPTYPE test; + + //FILETIME ftTime; + //GetSystemTimeAsFileTime(&ftTime); + std::vector buffer(sizeof(FILETIME)); + + SetupDiGetDevicePropertyW(hDeviceInfo, &deviceInfoData, &DEVPKEY_Device_LastArrivalDate, &test, buffer.data(), sizeof(FILETIME), nullptr, 0); + FILETIME filetime; + LARGE_INTEGER li; + + //TODO is this safe? + memmove(&filetime, buffer.data(), sizeof(FILETIME)); + li.LowPart=filetime.dwLowDateTime; + li.HighPart=filetime.dwHighDateTime; + FILETIME localFileTime; + FileTimeToLocalFileTime(&filetime, &localFileTime); + SYSTEMTIME systemTime; + FileTimeToSystemTime(&localFileTime, &systemTime); + //printf("Date %d/%d/%d\n", systemTime.wDay, systemTime.wMonth, systemTime.wYear); + //printf("Time: %d:%d:%d\n", systemTime.wHour, systemTime.wMinute, systemTime.wSecond); + //printf("%i", st); + device->attachTimestamp = (li.QuadPart-UNIX_TIME_START) / TICKS_PER_SECOND; } // end for (index = 0; ; index++) if (hDevice != INVALID_HANDLE_VALUE) { @@ -726,6 +778,7 @@ std::vector ListStorageDevices() { device.isVirtual = device.isVirtual || device.busType == "VIRTUAL" || device.busType == "FILEBACKEDVIRTUAL"; + device.attachTimestamp = device.attachTimestamp; } else if (device.error == "") { device.error = "Couldn't get detail data"; } diff --git a/target/npmlist.json b/target/npmlist.json new file mode 100644 index 00000000..9a9dc9e8 --- /dev/null +++ b/target/npmlist.json @@ -0,0 +1 @@ +{"version":"11.1.0","name":"drivelist","dependencies":{"bindings":{"version":"1.5.0"},"debug":{"version":"4.3.4"},"node-addon-api":{"version":"5.0.0"},"prebuild-install":{"version":"7.1.1"},"typescript":{"version":"4.9.4"}}} \ No newline at end of file From 4b5e1ab0ecdddd44f2b925e2ba45c8c639cb8371 Mon Sep 17 00:00:00 2001 From: MrSmoer <66489839+MrSmoer@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:47:02 +0100 Subject: [PATCH 2/7] format with prettier --- lib/lsblk/index.ts | 12 +++---- lib/lsblk/json.ts | 82 ++++++++++++++++++++++----------------------- lib/lsblk/pairs.ts | 16 ++++----- tests/lsblk.spec.ts | 3 +- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/lib/lsblk/index.ts b/lib/lsblk/index.ts index c800b239..a2205c5e 100644 --- a/lib/lsblk/index.ts +++ b/lib/lsblk/index.ts @@ -62,25 +62,23 @@ async function addDevicePaths(devices: Drive[]): Promise { for (const device of devices) { const path = devicePaths.get(device.device); device.devicePath = devicePaths.get(device.device) || null; - device.attachTimestamp= await getAttachTimestamp(path); + device.attachTimestamp = await getAttachTimestamp(path); } } async function getAttachTimestamp(path: string | undefined): Promise { - const fs = require('fs'); + const fsmodule = require('fs'); let time; try { - const stats= await fs.promises.stat(path) + const stats = await fsmodule.promises.stat(path); console.log(stats.mtime); time = stats.mtime.getTime(); } catch (err) { - time=0; + time = 0; console.error(err); } - + return time; - - } async function getOutput(command: string, ...args: string[]) { diff --git a/lib/lsblk/json.ts b/lib/lsblk/json.ts index 1d454856..88eff2cb 100644 --- a/lib/lsblk/json.ts +++ b/lib/lsblk/json.ts @@ -107,48 +107,46 @@ export function transform(data: LsblkJsonOutput): Drive[] { !device.name.startsWith('/dev/sr') && !device.name.startsWith('/dev/ram'), ) - .map( - (device: LsblkJsonOutputDevice): Drive => { - const isVirtual = device.subsystems - ? /^(block)$/i.test(device.subsystems) - : null; - const isSCSI = device.tran - ? /^(sata|scsi|ata|ide|pci)$/i.test(device.tran) - : null; - const isUSB = device.tran ? /^(usb)$/i.test(device.tran) : null; - const isReadOnly = Number(device.ro) === 1; - const isRemovable = - Number(device.rm) === 1 || - Number(device.hotplug) === 1 || - Boolean(isVirtual); - return { - enumerator: 'lsblk:json', - busType: (device.tran || 'UNKNOWN').toUpperCase(), - busVersion: null, - device: device.name, - devicePath: null, - raw: device.kname || device.name, - description: getDescription(device), - error: null, - size: Number(device.size) || null, - blockSize: Number(device['phy-sec']) || 512, - logicalBlockSize: Number(device['log-sec']) || 512, - mountpoints: device.children - ? getMountpoints(device.children) - : getMountpoints([device]), - isReadOnly, - isSystem: !isRemovable && !isVirtual, - isVirtual, - isRemovable, - isCard: null, - isSCSI, - isUSB, - isUAS: null, - partitionTableType: getPartitionTableType(device.pttype), - attachTimestamp: null - }; - }, - ); + .map((device: LsblkJsonOutputDevice): Drive => { + const isVirtual = device.subsystems + ? /^(block)$/i.test(device.subsystems) + : null; + const isSCSI = device.tran + ? /^(sata|scsi|ata|ide|pci)$/i.test(device.tran) + : null; + const isUSB = device.tran ? /^(usb)$/i.test(device.tran) : null; + const isReadOnly = Number(device.ro) === 1; + const isRemovable = + Number(device.rm) === 1 || + Number(device.hotplug) === 1 || + Boolean(isVirtual); + return { + enumerator: 'lsblk:json', + busType: (device.tran || 'UNKNOWN').toUpperCase(), + busVersion: null, + device: device.name, + devicePath: null, + raw: device.kname || device.name, + description: getDescription(device), + error: null, + size: Number(device.size) || null, + blockSize: Number(device['phy-sec']) || 512, + logicalBlockSize: Number(device['log-sec']) || 512, + mountpoints: device.children + ? getMountpoints(device.children) + : getMountpoints([device]), + isReadOnly, + isSystem: !isRemovable && !isVirtual, + isVirtual, + isRemovable, + isCard: null, + isSCSI, + isUSB, + isUAS: null, + partitionTableType: getPartitionTableType(device.pttype), + attachTimestamp: null, + }; + }); } export function parse(stdout: string): Drive[] { diff --git a/lib/lsblk/pairs.ts b/lib/lsblk/pairs.ts index 49d49b5e..9a2697ed 100644 --- a/lib/lsblk/pairs.ts +++ b/lib/lsblk/pairs.ts @@ -100,14 +100,12 @@ function consolidate( return Object.assign({}, device, { mountpoints: children .filter((child) => child.mountpoint) - .map( - (child): Mountpoint => { - return { - path: child.mountpoint, - label: child.label, - }; - }, - ), + .map((child): Mountpoint => { + return { + path: child.mountpoint, + label: child.label, + }; + }), }); }); } @@ -182,7 +180,7 @@ export function parse(stdout: string): Drive[] { partitionTableType: getPartitionTableType( device.pttype as 'gpt' | 'dos' | undefined, ), - attachTimestamp: null + attachTimestamp: null, }; }, ); diff --git a/tests/lsblk.spec.ts b/tests/lsblk.spec.ts index 891b3762..40959b5c 100644 --- a/tests/lsblk.spec.ts +++ b/tests/lsblk.spec.ts @@ -330,8 +330,7 @@ describe('Drivelist', () => { label: undefined, }, { - path: - '/tmp/media/3E3E-E910 (\\xe2\\x88\\x95dev\\xe2\\x88\\x95sdi)', + path: '/tmp/media/3E3E-E910 (\\xe2\\x88\\x95dev\\xe2\\x88\\x95sdi)', label: undefined, }, ], From 1675d4034d8a83de498b42b49d72dd69dde1dab6 Mon Sep 17 00:00:00 2001 From: Mister Smoer Date: Wed, 25 Jan 2023 23:52:49 +0100 Subject: [PATCH 3/7] A little bit cleanup --- src/darwin/list.mm | 6 +----- src/windows/list.cpp | 22 ++++++---------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/darwin/list.mm b/src/darwin/list.mm index 71883d68..a5a62e0c 100644 --- a/src/darwin/list.mm +++ b/src/darwin/list.mm @@ -105,11 +105,7 @@ DeviceDescriptor CreateDeviceDescriptorFromDiskDescription(std::string diskBsdNa NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *path = [NSString stringWithUTF8String:("/dev/"+diskBsdName).c_str()]; NSDate *dates = [[fileManager attributesOfItemAtPath:path error:NULL] fileModificationDate]; - //TODO path can be null and remove debug - NSLog(@"Unix time: %@", dates); - NSTimeInterval unixTime = [dates timeIntervalSince1970]; - NSLog(@"real Unix time: %f",unixTime); - device.attachTimestamp = unixTime; + device.attachTimestamp = ((dates != nil) ? [dates timeIntervalSince1970] : 0); return device; } diff --git a/src/windows/list.cpp b/src/windows/list.cpp index 08570598..826e2aee 100644 --- a/src/windows/list.cpp +++ b/src/windows/list.cpp @@ -672,42 +672,32 @@ bool GetDetailData(DeviceDescriptor* device, NULL, 0, &size, NULL); device->isReadOnly = !isWritable; + const int64_t UNIX_TIME_START= 0x019DB1DED53E8000; const int64_t TICKS_PER_SECOND = 10000000; DWORD requiredSize; DEVPROPTYPE type; - WCHAR szBuffer[4096]; - BOOL hasArrivalDate = SetupDiGetDevicePropertyW(hDeviceInfo, &deviceInfoData, &DEVPKEY_Device_LastArrivalDate, - &type, (BYTE*)szBuffer, sizeof(FILETIME), &requiredSize, 0); + SetupDiGetDevicePropertyW(hDeviceInfo, &deviceInfoData, &DEVPKEY_Device_LastArrivalDate, + &type, NULL, 0, &requiredSize, 0); + std::vector buffer(requiredSize*8); + BOOL hasArrivalDate = SetupDiGetDevicePropertyW(hDeviceInfo, &deviceInfoData, &DEVPKEY_Device_LastArrivalDate, &type, buffer.data(), buffer.capacity(), nullptr, 0); if (!hasArrivalDate) { errorCode = GetLastError(); device->error = "Couldn't SetupDiGetDeviceInterfaceDetailW: Error " + std::to_string(errorCode); result = false; break; - } - DEVPROPTYPE test; - - //FILETIME ftTime; - //GetSystemTimeAsFileTime(&ftTime); - std::vector buffer(sizeof(FILETIME)); - - SetupDiGetDevicePropertyW(hDeviceInfo, &deviceInfoData, &DEVPKEY_Device_LastArrivalDate, &test, buffer.data(), sizeof(FILETIME), nullptr, 0); FILETIME filetime; LARGE_INTEGER li; - //TODO is this safe? - memmove(&filetime, buffer.data(), sizeof(FILETIME)); + memmove(&filetime, buffer.data(), buffer.capacity()); li.LowPart=filetime.dwLowDateTime; li.HighPart=filetime.dwHighDateTime; FILETIME localFileTime; FileTimeToLocalFileTime(&filetime, &localFileTime); SYSTEMTIME systemTime; FileTimeToSystemTime(&localFileTime, &systemTime); - //printf("Date %d/%d/%d\n", systemTime.wDay, systemTime.wMonth, systemTime.wYear); - //printf("Time: %d:%d:%d\n", systemTime.wHour, systemTime.wMinute, systemTime.wSecond); - //printf("%i", st); device->attachTimestamp = (li.QuadPart-UNIX_TIME_START) / TICKS_PER_SECOND; } // end for (index = 0; ; index++) From e5ea7f23131a961fc257a63006ccf4f6e5bf9339 Mon Sep 17 00:00:00 2001 From: Mister Smoer Date: Thu, 26 Jan 2023 00:15:57 +0100 Subject: [PATCH 4/7] adapt tests --- tests/lsblk.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/lsblk.spec.ts b/tests/lsblk.spec.ts index 40959b5c..d978f892 100644 --- a/tests/lsblk.spec.ts +++ b/tests/lsblk.spec.ts @@ -80,6 +80,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, ]; @@ -118,6 +119,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, { enumerator: 'lsblk:pairs', @@ -150,6 +152,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, ]; @@ -190,6 +193,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, { enumerator: 'lsblk:json', @@ -226,6 +230,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, ]; @@ -263,6 +268,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, { enumerator: 'lsblk:pairs', @@ -286,6 +292,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, { enumerator: 'lsblk:pairs', @@ -309,6 +316,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, { enumerator: 'lsblk:pairs', @@ -342,6 +350,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, { enumerator: 'lsblk:pairs', @@ -370,6 +379,7 @@ describe('Drivelist', () => { isSCSI: null, isUSB: null, isUAS: null, + attachTimestamp: null, }, ]; @@ -387,6 +397,7 @@ describe('Drivelist', () => { const expected = [ { + attachTimestamp: null, blockSize: 512, busType: 'UNKNOWN', busVersion: null, @@ -419,6 +430,7 @@ describe('Drivelist', () => { size: 240065183744, }, { + attachTimestamp: null, blockSize: 512, busType: 'UNKNOWN', busVersion: null, @@ -442,6 +454,7 @@ describe('Drivelist', () => { size: null, }, { + attachTimestamp: null, blockSize: 512, busType: 'UNKNOWN', busVersion: null, From 7960dc5e362357ef2ed580b4f0a13cfb1574663d Mon Sep 17 00:00:00 2001 From: MrSmoer <66489839+MrSmoer@users.noreply.github.com> Date: Mon, 21 Aug 2023 23:12:05 +0200 Subject: [PATCH 5/7] small comment to bump ci again --- src/windows/list.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/windows/list.cpp b/src/windows/list.cpp index 826e2aee..6b51a11a 100644 --- a/src/windows/list.cpp +++ b/src/windows/list.cpp @@ -686,6 +686,7 @@ bool GetDetailData(DeviceDescriptor* device, device->error = "Couldn't SetupDiGetDeviceInterfaceDetailW: Error " + std::to_string(errorCode); result = false; + //TOOD is it right to break here? break; } FILETIME filetime; From e5e3235c945297946ae2f37cdbe06c48ab698041 Mon Sep 17 00:00:00 2001 From: MrSmoer <66489839+MrSmoer@users.noreply.github.com> Date: Mon, 21 Aug 2023 23:25:51 +0200 Subject: [PATCH 6/7] comment and bump ci Change-type: minor --- src/windows/list.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/windows/list.cpp b/src/windows/list.cpp index 6b51a11a..59e3c19c 100644 --- a/src/windows/list.cpp +++ b/src/windows/list.cpp @@ -695,10 +695,12 @@ bool GetDetailData(DeviceDescriptor* device, memmove(&filetime, buffer.data(), buffer.capacity()); li.LowPart=filetime.dwLowDateTime; li.HighPart=filetime.dwHighDateTime; + //is this even necessary? FILETIME localFileTime; FileTimeToLocalFileTime(&filetime, &localFileTime); SYSTEMTIME systemTime; FileTimeToSystemTime(&localFileTime, &systemTime); + device->attachTimestamp = (li.QuadPart-UNIX_TIME_START) / TICKS_PER_SECOND; } // end for (index = 0; ; index++) From dc823ae771a34f802f71dd7419aa7037741c5bfa Mon Sep 17 00:00:00 2001 From: Mister Smoer Date: Tue, 22 Aug 2023 02:54:06 +0200 Subject: [PATCH 7/7] don't break and add default value for windows --- src/windows/list.cpp | 5 +++-- tests/drivelist.spec.ts | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/windows/list.cpp b/src/windows/list.cpp index 59e3c19c..f5dbe8cb 100644 --- a/src/windows/list.cpp +++ b/src/windows/list.cpp @@ -673,6 +673,7 @@ bool GetDetailData(DeviceDescriptor* device, device->isReadOnly = !isWritable; + device->attachTimestamp = NULL; const int64_t UNIX_TIME_START= 0x019DB1DED53E8000; const int64_t TICKS_PER_SECOND = 10000000; DWORD requiredSize; @@ -685,9 +686,9 @@ bool GetDetailData(DeviceDescriptor* device, errorCode = GetLastError(); device->error = "Couldn't SetupDiGetDeviceInterfaceDetailW: Error " + std::to_string(errorCode); - result = false; + //result = false; //TOOD is it right to break here? - break; + //break; } FILETIME filetime; LARGE_INTEGER li; diff --git a/tests/drivelist.spec.ts b/tests/drivelist.spec.ts index e14ecdbe..0bfbf4dc 100644 --- a/tests/drivelist.spec.ts +++ b/tests/drivelist.spec.ts @@ -84,6 +84,10 @@ describe('Drivelist', () => { device.isUAS === null || typeof device.isUAS === 'boolean', `Invalid isUAS flag: ${device.isUAS}`, ); + ok( + device.attachTimestamp === null || Number.isFinite(device.attachTimestamp), + `Invalid attachTimestamp: ${device.attachTimestamp}`, + ); }); });