Skip to content

Commit

Permalink
fix(suite-desktop-core): use checkFileExits form node-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
karliatto committed Aug 6, 2024
1 parent 90b029d commit 5e783fa
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/suite-desktop-core/src/modules/udev-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@ import path from 'path';
import { spawn } from 'child_process';

import { validateIpcMessage } from '@trezor/ipc-proxy';
import { checkFileExists } from '@trezor/node-utils';

import { app, ipcMain } from '../typed-electron';

import type { Module } from './index';

const FILE_NAME = '51-trezor.rules';

const fileExists = async (filePath: string) => {
try {
await fs.promises.stat(filePath);

return true;
} catch (error) {
// file is not present
}

return false;
};

export const SERVICE_NAME = 'udev';

export const init: Module = () => {
Expand All @@ -35,15 +24,15 @@ export const init: Module = () => {

logger.info(SERVICE_NAME, `Installing ${resourceRules} > ${userRules} > ${distRules}`);

if (await fileExists(distRules)) {
if (await checkFileExists(distRules)) {
logger.error(SERVICE_NAME, `/etc/udev rules already installed: ${distRules}`);

// /etc/udev already exists, break here.
// TODO: should override anyway?
return { success: false, error: `File ${distRules} already exists` };
}

if (!(await fileExists(userRules))) {
if (!(await checkFileExists(userRules))) {
try {
logger.info(SERVICE_NAME, `Create user data rules: ${userRules}`);
// copy rules from app resources (/tmp/...) to user data files (~/.cache/...)
Expand Down

0 comments on commit 5e783fa

Please sign in to comment.