Skip to content

Commit 3017c13

Browse files
committed
get pciids from code if not found on filesystem
1 parent bc85403 commit 3017c13

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

HIRS_Utils/src/main/java/hirs/utils/PciIds.java

+27-13
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public final class PciIds {
3636
/**
3737
* Name of pciids file in code.
3838
*/
39-
private static final String PCIIDS_FILENAME = "pci.ids";
39+
private static final String PCIIDS_FILENAME = "/pci.ids";
4040

4141
/**
4242
* This pci ids file can be in different places on different distributions.
@@ -65,6 +65,8 @@ public final class PciIds {
6565
//Configure the PCI IDs Database object.
6666
static {
6767
if (!DB.isReady()) {
68+
69+
// if pciids file is found on the system, then process using this
6870
String dbFile = null;
6971
for (final String path : PCI_IDS_PATH) {
7072
if ((new File(path)).exists()) {
@@ -73,21 +75,13 @@ public final class PciIds {
7375
break;
7476
}
7577
}
76-
// if pciids file is not found on the system, then attempt to grab it from code
78+
7779
if(dbFile != null) {
78-
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
79-
}
80-
else {
81-
dbFile = PciIds.class.getResource(PCIIDS_FILENAME).getPath();
82-
}
83-
if (dbFile != null) {
84-
if (!pciidsFileStatus.equals(UefiConstants.FILESTATUS_FROM_FILESYSTEM)) {
85-
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE;
86-
}
8780
InputStream is = null;
8881
try {
8982
is = new FileInputStream(new File(dbFile));
9083
DB.loadStream(is);
84+
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_FILESYSTEM;
9185
} catch (IOException e) {
9286
// DB will not be ready, hardware IDs will not be translated
9387
dbFile = null;
@@ -101,8 +95,28 @@ public final class PciIds {
10195
}
10296
}
10397
}
104-
else {
105-
log.info("PCI IDs file was NOT found");
98+
99+
// if pciids file is not found on the system or not accessible, then attempt to grab it from code
100+
if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) {
101+
InputStream istemp = PciIds.class.getResourceAsStream(PCIIDS_FILENAME);
102+
try {
103+
DB.loadStream(istemp);
104+
pciidsFileStatus = UefiConstants.FILESTATUS_FROM_CODE;
105+
} catch (IOException e) {
106+
// DB will not be ready, hardware IDs will not be translated
107+
} finally {
108+
if (istemp != null) {
109+
try {
110+
istemp.close();
111+
} catch (IOException e) {
112+
}
113+
}
114+
}
115+
}
116+
117+
// if pciids file is not accessible on system or from within code, then log error
118+
if(pciidsFileStatus == UefiConstants.FILESTATUS_NOT_ACCESSIBLE) {
119+
log.info("PCI IDs file was NOT accessible from within the system or within the code");
106120
}
107121
}
108122
}

0 commit comments

Comments
 (0)