Only read directories under /sys/class/net

When reading mac addresses, if there is a non-directory file under
/sys/class/net, this will cause the supervisor to show an exception on
the logs. This now filters out non-directories on the list to prevent
this

Change-type: patch
This commit is contained in:
Felipe Lalanne 2024-07-23 11:11:00 -04:00
parent 649a20fbe0
commit 19de8e6263

View File

@ -17,12 +17,24 @@ export async function getAll(sysClassNet: string): Promise<string | undefined> {
return _(
await Promise.all(
interfaces.map(async (intf) => {
const ifacePath = path.join(sysClassNet, intf);
try {
// Exclude non-directories
const entryStat = await fs.stat(ifacePath);
if (!entryStat.isDirectory()) {
return '';
}
} catch {
// If stat fails ignore the interface
return '';
}
try {
const [addressFile, typeFile, masterFile] = [
'address',
'type',
'master',
].map((f) => path.join(sysClassNet, intf, f));
].map((f) => path.join(ifacePath, f));
const [intfType, intfHasMaster] = await Promise.all([
fs.readFile(typeFile, 'utf8'),