Skip to content

Commit

Permalink
Only read directories under /sys/class/net
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pipex committed Jul 29, 2024
1 parent c399792 commit cce57d4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/mac-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit cce57d4

Please sign in to comment.