Skip to content

Commit

Permalink
fix updateStartupScript in node v0.12.x
Browse files Browse the repository at this point in the history
Buffer.indexOf() doesn't exist in old Node.js, so read the file into a
string instead.

This fixes "TypeError: undefined is not a function" when calling
updateStartupScript.

Also return a stack trace in the Luna payload on error to aid in
debugging any future issues.
  • Loading branch information
throwaway96 committed Aug 11, 2023
1 parent d2389de commit d22d827
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion services/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const asyncExecFile: (
) => Promise<string> = Bluebird.Promise.promisify(execFile);
export const asyncStat: (path: string) => Promise<fs.Stats> = Bluebird.Promise.promisify(fs.stat);
export const asyncUnlink: (path: string) => Promise<void> = Bluebird.Promise.promisify(fs.unlink);
export const asyncReadFile: (path: string, options?: any) => Promise<Buffer> = Bluebird.Promise.promisify(fs.readFile);
export const asyncReadFile: (path: string, options?: any) => Promise<Buffer | string> = Bluebird.Promise.promisify(fs.readFile);
export const asyncWriteFile: (path: string, contents: string, options?: fs.WriteFileOptions) => Promise<void> = Bluebird.Promise.promisify(
fs.writeFile,
);
Expand Down
9 changes: 7 additions & 2 deletions services/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,20 +527,25 @@ function runService() {
// RootMyTV v1
if (await isFile(startDevmode)) {
const localChecksum = await hashFile(startDevmode, 'sha256');
// Warn and return empty string on read error
let startDevmodeContents = await asyncReadFile(startDevmode, { encoding: 'utf-8'} )
.catch((err) => (console.warn(`reading ${startDevmode} failed: ${err.toString()}`), '')) as string;

if (localChecksum !== bundledStartupChecksum && updatableChecksums.indexOf(localChecksum) !== -1) {
await copyScript(bundledStartup, startDevmode);
messages.push(`${startDevmode} updated!`);
} else if (localChecksum !== bundledJumpstartChecksum && (await asyncReadFile(startDevmode)).indexOf('org.webosbrew') !== -1) {
} else if (localChecksum !== bundledJumpstartChecksum && startDevmodeContents.indexOf('org.webosbrew') !== -1) {
// Show notification about mismatched startup script if contains
// org.webosbrew string (which is not used on jumpstart.sh nor
// official start-devmode.sh)
messages.push(`${startDevmode} has been manually modified!`);
}
}
} catch (err) {
console.log(`Startup script update failed: ${err.stack}`);
messages = ['Startup script update failed!', ...messages, `Error: ${err.toString()}`];
await createToast(messages.join('<br/>'), service);
return { returnValue: false, statusText: 'Startup script update failed.', messages };
return { returnValue: false, statusText: 'Startup script update failed.', stack: err.stack, messages };
}

if (messages.length) {
Expand Down

0 comments on commit d22d827

Please sign in to comment.