Skip to content

Commit

Permalink
Merge pull request webosbrew#175 from throwaway96/rm-exists-20240307
Browse files Browse the repository at this point in the history
Replace deprecated fs.exists()
  • Loading branch information
throwaway96 authored Mar 9, 2024
2 parents 6fdd700 + b44d593 commit f4a6e59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 0 additions & 4 deletions services/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,4 @@ export const asyncWriteFile: (path: string, contents: string, options?: fs.Write
fs.writeFile,
);
export const asyncChmod: (path: string, mode: fs.Mode) => Promise<void> = Bluebird.Promise.promisify(fs.chmod);
export const asyncExists: (path: string) => Promise<boolean> = (path) =>
new Promise((resolve) => {
fs.exists(path, resolve);
});
export const asyncMkdir: (path: string, mode?: fs.Mode) => Promise<void> = Bluebird.Promise.promisify(fs.mkdir);
28 changes: 14 additions & 14 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ import { Promise } from 'bluebird'; // eslint-disable-line @typescript-eslint/no
import progress from 'progress-stream';
import Service, { Message } from 'webos-service';
import fetch from 'node-fetch';
import {
asyncStat,
asyncExecFile,
asyncPipeline,
asyncUnlink,
asyncWriteFile,
asyncReadFile,
asyncChmod,
asyncExists,
asyncMkdir,
} from './adapter';
import { asyncStat, asyncExecFile, asyncPipeline, asyncUnlink, asyncWriteFile, asyncReadFile, asyncChmod, asyncMkdir } from './adapter';

import rootAppInfo from '../appinfo.json';
import serviceInfo from './services.json';
Expand Down Expand Up @@ -106,6 +96,16 @@ async function isFile(targetPath: string): Promise<boolean> {
}
}

/**
* Check whether a path exists
*/
function exists(targetPath: string): Promise<boolean> {
return asyncStat(targetPath).then(
() => true,
() => false,
);
}

/**
* Copies a file
*/
Expand Down Expand Up @@ -169,7 +169,7 @@ function flagFilePath(flagFile: FlagFileName): string {
* Returns whether a flag is set or not.
*/
async function flagFileRead(flagFile: FlagFileName): Promise<boolean> {
return asyncExists(flagFilePath(flagFile));
return exists(flagFilePath(flagFile));
}

/**
Expand Down Expand Up @@ -785,11 +785,11 @@ function runService(): void {
if (!runningAsRoot) {
return { message: 'Not running as root.', returnValue: true };
}
if (await asyncExists('/tmp/webosbrew_startup')) {
if (await exists('/tmp/webosbrew_startup')) {
return { message: 'Startup script already executed.', returnValue: true };
}
// Copy startup.sh if doesn't exist
if (!(await asyncExists('/var/lib/webosbrew/startup.sh'))) {
if (!(await exists('/var/lib/webosbrew/startup.sh'))) {
try {
await asyncMkdir('/var/lib/webosbrew/', 0o755);
} catch {
Expand Down

0 comments on commit f4a6e59

Please sign in to comment.