Skip to content

Commit

Permalink
Use the promises namespace of balena-image-fs
Browse files Browse the repository at this point in the history
Update balena-image-fs from 7.0.6 to 7.3.0

Change-type: patch
  • Loading branch information
thgreasi committed Jan 7, 2025
1 parent f0f26e0 commit de0af08
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"dependencies": {
"balena-config-json": "^4.2.0",
"balena-image-fs": "^7.0.6",
"balena-image-fs": "^7.3.0",
"balena-semver": "^2.2.0",
"lodash": "^4.17.15",
"reconfix": "1.0.0-v0-1-0-fork-46760acff4d165f5238bfac5e464256ef1944476",
Expand Down
3 changes: 3 additions & 0 deletions repo.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
type: 'node'
upstream:
- repo: 'balena-image-fs'
url: 'https://github.com/balena-io-modules/balena-image-fs'
39 changes: 20 additions & 19 deletions src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ limitations under the License.

import _ from 'lodash';
import path from 'path';
import * as util from 'node:util';
import * as imagefs from 'balena-image-fs';
import reconfix from 'reconfix';
import * as utils from './utils';
Expand Down Expand Up @@ -121,11 +120,10 @@ const prepareImageOS1NetworkConfig = function (
configFilePath.image,
configFilePath.partition,
function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
const writeFileAsync = util.promisify(_fs.writeFile);
return readFileAsync(configFilePath.path, {
encoding: 'utf8',
})
return _fs.promises
.readFile(configFilePath.path, {
encoding: 'utf8',
})
.catch((e) => {
if (fileNotFoundError(e)) {
return '{}';
Expand All @@ -140,7 +138,10 @@ const prepareImageOS1NetworkConfig = function (
if (contents.files['network/network.config'] == null) {
contents.files['network/network.config'] = '';
}
return writeFileAsync(configFilePath.path, JSON.stringify(contents));
return _fs.promises.writeFile(
configFilePath.path,
JSON.stringify(contents),
);
});
},
);
Expand Down Expand Up @@ -180,8 +181,7 @@ const prepareImageOS2WifiConfig = async function (
inputDefinition.image,
inputDefinition.partition,
function (_fs) {
const readdirAsync = util.promisify(_fs.readdir);
return readdirAsync(CONNECTIONS_FOLDER);
return _fs.promises.readdir(CONNECTIONS_FOLDER);
},
);

Expand All @@ -196,15 +196,16 @@ const prepareImageOS2WifiConfig = async function (
inputDefinition.image,
inputDefinition.partition,
async function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
const writeFileAsync = util.promisify(_fs.writeFile);
const contents = await readFileAsync(
const contents = await _fs.promises.readFile(
`${CONNECTIONS_FOLDER}/resin-sample.ignore`,
{
encoding: 'utf8',
},
);
await writeFileAsync(`${CONNECTIONS_FOLDER}/resin-wifi`, contents);
await _fs.promises.writeFile(
`${CONNECTIONS_FOLDER}/resin-wifi`,
contents,
);
},
);
return;
Expand All @@ -216,15 +217,16 @@ const prepareImageOS2WifiConfig = async function (
inputDefinition.image,
inputDefinition.partition,
async function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
const writeFileAsync = util.promisify(_fs.writeFile);
const contents = await readFileAsync(
const contents = await _fs.promises.readFile(
`${CONNECTIONS_FOLDER}/resin-sample`,
{
encoding: 'utf8',
},
);
await writeFileAsync(`${CONNECTIONS_FOLDER}/resin-wifi`, contents);
await _fs.promises.writeFile(
`${CONNECTIONS_FOLDER}/resin-wifi`,
contents,
);
},
);
return;
Expand All @@ -235,8 +237,7 @@ const prepareImageOS2WifiConfig = async function (
inputDefinition.image,
inputDefinition.partition,
async function (_fs) {
const writeFileAsync = util.promisify(_fs.writeFile);
await writeFileAsync(
await _fs.promises.writeFile(
`${CONNECTIONS_FOLDER}/resin-wifi`,
DEFAULT_CONNECTION_FILE,
);
Expand Down
10 changes: 3 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.

import _ from 'lodash';
import path from 'path';
import * as util from 'node:util';
import * as imagefs from 'balena-image-fs';
import { getBootPartition } from 'balena-config-json';

Expand Down Expand Up @@ -48,8 +47,7 @@ export async function getImageManifest(
image,
bootPartitionNumber,
function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/device-type.json', {
return _fs.promises.readFile('/device-type.json', {
encoding: 'utf8',
});
},
Expand Down Expand Up @@ -167,8 +165,7 @@ export async function getImageOsVersion(
definition.image,
definition.partition,
function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/os-release', { encoding: 'utf8' });
return _fs.promises.readFile('/os-release', { encoding: 'utf8' });
},
);

Expand Down Expand Up @@ -235,8 +232,7 @@ export const writeConfigJSON = function (
definitionWithImage.image,
definitionWithImage.partition,
function (_fs) {
const writeFileAsync = util.promisify(_fs.writeFile);
return writeFileAsync(definitionWithImage.path, serializedConfig);
return _fs.promises.writeFile(definitionWithImage.path, serializedConfig);
},
);
};
16 changes: 5 additions & 11 deletions tests/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as sinon from 'sinon';
import * as fsPromise from 'fs/promises';
import * as fs from 'fs';
import path from 'path';
import * as util from 'node:util';
import wary from 'wary';

import * as settings from 'balena-settings-client';
Expand Down Expand Up @@ -73,8 +72,7 @@ wary.it(
.then(waitStream)
.then(() =>
imagefs.interact(images.raspberrypi, 1, function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/config.json', { encoding: 'utf8' });
return _fs.promises.readFile('/config.json', { encoding: 'utf8' });
}),
)
.then(JSON.parse)
Expand All @@ -101,8 +99,7 @@ wary.it(
.then(waitStream)
.then(() =>
imagefs.interact(images.raspberrypi, 5, function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/config.json', { encoding: 'utf8' });
return _fs.promises.readFile('/config.json', { encoding: 'utf8' });
}),
)
.then(JSON.parse)
Expand Down Expand Up @@ -130,8 +127,7 @@ wary.it(
.then(waitStream)
.then(() =>
imagefs.interact(images.raspberrypi, 1, function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/config.json', { encoding: 'utf8' });
return _fs.promises.readFile('/config.json', { encoding: 'utf8' });
}),
)
.then(JSON.parse)
Expand Down Expand Up @@ -169,8 +165,7 @@ wary.it(
.then(waitStream)
.then(() =>
imagefs.interact(images.raspberrypi, 1, function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/system-connections/resin-wifi', {
return _fs.promises.readFile('/system-connections/resin-wifi', {
encoding: 'utf8',
});
}),
Expand Down Expand Up @@ -408,8 +403,7 @@ wary.it(
path.join(images.edison, 'resin-image-edison.hddimg'),
undefined,
function (_fs) {
const readFileAsync = util.promisify(_fs.readFile);
return readFileAsync('/config.json', { encoding: 'utf8' });
return _fs.promises.readFile('/config.json', { encoding: 'utf8' });
},
),
)
Expand Down

0 comments on commit de0af08

Please sign in to comment.