Skip to content

Commit 29e7827

Browse files
committedJan 9, 2025
Use the promises namespace of balena-image-fs
Change-type: patch
1 parent 1d77cf3 commit 29e7827

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed
 

‎src/commands/local/configure.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import { Args, Command } from '@oclif/core';
19-
import { promisify } from 'util';
2019
import { stripIndent } from '../../utils/lazy';
2120

2221
export default class LocalConfigureCmd extends Command {
@@ -237,7 +236,7 @@ export default class LocalConfigureCmd extends Command {
237236
const bootPartition = await getBootPartition(target);
238237

239238
const files = await imagefs.interact(target, bootPartition, async (_fs) => {
240-
return await promisify(_fs.readdir)(this.CONNECTIONS_FOLDER);
239+
return await _fs.promises.readdir(this.CONNECTIONS_FOLDER);
241240
});
242241

243242
let connectionFileName;
@@ -246,13 +245,14 @@ export default class LocalConfigureCmd extends Command {
246245
} else if (_.includes(files, 'resin-sample.ignore')) {
247246
// Fresh image, new mode, accoding to https://github.com/balena-os/meta-balena/pull/770/files
248247
await imagefs.interact(target, bootPartition, async (_fs) => {
249-
const readFileAsync = promisify(_fs.readFile);
250-
const writeFileAsync = promisify(_fs.writeFile);
251-
const contents = await readFileAsync(
248+
const contents = await _fs.promises.readFile(
252249
`${this.CONNECTIONS_FOLDER}/resin-sample.ignore`,
253250
{ encoding: 'utf8' },
254251
);
255-
await writeFileAsync(`${this.CONNECTIONS_FOLDER}/resin-wifi`, contents);
252+
await _fs.promises.writeFile(
253+
`${this.CONNECTIONS_FOLDER}/resin-wifi`,
254+
contents,
255+
);
256256
});
257257
} else if (_.includes(files, 'resin-sample')) {
258258
// Legacy mode, to be removed later
@@ -266,7 +266,7 @@ export default class LocalConfigureCmd extends Command {
266266
} else {
267267
// In case there's no file at all (shouldn't happen normally, but the file might have been removed)
268268
await imagefs.interact(target, bootPartition, async (_fs) => {
269-
await promisify(_fs.writeFile)(
269+
await _fs.promises.writeFile(
270270
`${this.CONNECTIONS_FOLDER}/resin-wifi`,
271271
this.CONNECTION_FILE,
272272
);

‎src/commands/os/configure.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import { Flags, Args, Command } from '@oclif/core';
1919
import type { Interfaces } from '@oclif/core';
2020
import type * as BalenaSdk from 'balena-sdk';
21-
import { promisify } from 'util';
2221
import * as _ from 'lodash';
2322
import { ExpectedError } from '../../errors';
2423
import * as cf from '../../utils/common-flags';
@@ -292,7 +291,7 @@ export default class OsConfigureCmd extends Command {
292291

293292
for (const { name, content } of files) {
294293
await imagefs.interact(image, bootPartition, async (_fs) => {
295-
await promisify(_fs.writeFile)(
294+
await _fs.promises.writeFile(
296295
path.join(CONNECTIONS_FOLDER, name),
297296
content,
298297
);

‎tests/commands/os/configure.spec.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,22 @@ if (process.platform !== 'win32') {
6262
tmpNonMatchingDtJsonPartitionPath,
6363
12,
6464
async (_fs) => {
65-
const readFileAsync = promisify(_fs.readFile);
66-
const writeFileAsync = promisify(_fs.writeFile);
67-
6865
const dtJson = JSON.parse(
69-
await readFileAsync('/device-type.json', { encoding: 'utf8' }),
66+
await _fs.promises.readFile('/device-type.json', {
67+
encoding: 'utf8',
68+
}),
7069
);
7170
expect(dtJson).to.have.nested.property(
7271
'configuration.config.partition',
7372
12,
7473
);
7574
dtJson.configuration.config.partition = 999;
76-
await writeFileAsync('/device-type.json', JSON.stringify(dtJson));
75+
await _fs.promises.writeFile(
76+
'/device-type.json',
77+
JSON.stringify(dtJson),
78+
);
7779

78-
await writeFileAsync(
80+
await _fs.promises.writeFile(
7981
'/os-release',
8082
stripIndent`
8183
ID="balena-os"
@@ -133,16 +135,17 @@ if (process.platform !== 'win32') {
133135
tmpMatchingDtJsonPartitionPath,
134136
12,
135137
async (_fs) => {
136-
const readFileAsync = promisify(_fs.readFile);
137138
const dtJson = JSON.parse(
138-
await readFileAsync('/device-type.json', { encoding: 'utf8' }),
139+
await _fs.promises.readFile('/device-type.json', {
140+
encoding: 'utf8',
141+
}),
139142
);
140143
// confirm that the device-type.json mentions the expected partition
141144
expect(dtJson).to.have.nested.property(
142145
'configuration.config.partition',
143146
12,
144147
);
145-
return await readFileAsync('/config.json');
148+
return await _fs.promises.readFile('/config.json');
146149
},
147150
);
148151
expect(config).to.not.be.empty;
@@ -180,16 +183,17 @@ if (process.platform !== 'win32') {
180183
tmpNonMatchingDtJsonPartitionPath,
181184
12,
182185
async (_fs) => {
183-
const readFileAsync = promisify(_fs.readFile);
184186
const dtJson = JSON.parse(
185-
await readFileAsync('/device-type.json', { encoding: 'utf8' }),
187+
await _fs.promises.readFile('/device-type.json', {
188+
encoding: 'utf8',
189+
}),
186190
);
187191
// confirm that the device-type.json mentions the expected partition
188192
expect(dtJson).to.have.nested.property(
189193
'configuration.config.partition',
190194
999,
191195
);
192-
return await readFileAsync('/config.json');
196+
return await _fs.promises.readFile('/config.json');
193197
},
194198
);
195199
expect(config).to.not.be.empty;
@@ -240,7 +244,7 @@ if (process.platform !== 'win32') {
240244

241245
// confirm the image contains a config.json...
242246
const config = await imagefs.interact(tmpDummyPath, 1, async (_fs) => {
243-
return await promisify(_fs.readFile)('/config.json');
247+
return await _fs.promises.readFile('/config.json');
244248
});
245249
expect(config).to.not.be.empty;
246250

0 commit comments

Comments
 (0)
Please sign in to comment.