mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-31 08:25:36 +00:00
Modify configuration backends to use readFromBoot
This ensures all reads from the boot partition are made using fatrw
This commit is contained in:
parent
c6f5af1fd9
commit
675bfc8873
@ -103,7 +103,10 @@ export class ConfigFs extends ConfigBackend {
|
||||
|
||||
// read the config file...
|
||||
try {
|
||||
const content = await fs.readFile(this.ConfigFilePath, 'utf8');
|
||||
const content = await hostUtils.readFromBoot(
|
||||
this.ConfigFilePath,
|
||||
'utf-8',
|
||||
);
|
||||
return JSON.parse(content);
|
||||
} catch (err) {
|
||||
log.error('Unable to deserialise ConfigFS configuration.', err);
|
||||
|
@ -1,5 +1,4 @@
|
||||
import * as _ from 'lodash';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
import { ConfigOptions, ConfigBackend } from './backend';
|
||||
import * as constants from '../../lib/constants';
|
||||
@ -64,7 +63,10 @@ export class ConfigTxt extends ConfigBackend {
|
||||
let configContents = '';
|
||||
|
||||
if (await exists(ConfigTxt.bootConfigPath)) {
|
||||
configContents = await fs.readFile(ConfigTxt.bootConfigPath, 'utf-8');
|
||||
configContents = await hostUtils.readFromBoot(
|
||||
ConfigTxt.bootConfigPath,
|
||||
'utf-8',
|
||||
);
|
||||
} else {
|
||||
await hostUtils.writeToBoot(ConfigTxt.bootConfigPath, '');
|
||||
}
|
||||
|
@ -59,7 +59,10 @@ export class Extlinux extends ConfigBackend {
|
||||
let confContents: string;
|
||||
|
||||
try {
|
||||
confContents = await fs.readFile(Extlinux.bootConfigPath, 'utf-8');
|
||||
confContents = await hostUtils.readFromBoot(
|
||||
Extlinux.bootConfigPath,
|
||||
'utf-8',
|
||||
);
|
||||
} catch {
|
||||
// In the rare case where the user might have deleted extlinux conf file between linux boot and supervisor boot
|
||||
// We do not have any backup to fallback too; warn the user of a possible brick
|
||||
|
@ -1,5 +1,4 @@
|
||||
import * as _ from 'lodash';
|
||||
import { promises as fs } from 'fs';
|
||||
|
||||
import { ConfigOptions, ConfigBackend } from './backend';
|
||||
import * as constants from '../../lib/constants';
|
||||
@ -195,7 +194,7 @@ export class ExtraUEnv extends ConfigBackend {
|
||||
|
||||
private static async readBootConfigPath(): Promise<string> {
|
||||
try {
|
||||
return await fs.readFile(ExtraUEnv.bootConfigPath, 'utf-8');
|
||||
return await hostUtils.readFromBoot(ExtraUEnv.bootConfigPath, 'utf-8');
|
||||
} catch {
|
||||
// In the rare case where the user might have deleted extra_uEnv conf file between linux boot and supervisor boot
|
||||
// We do not have any backup to fallback too; warn the user of a possible brick
|
||||
|
@ -71,7 +71,7 @@ export class SplashImage extends ConfigBackend {
|
||||
where = where ?? (await this.getSplashPath());
|
||||
|
||||
// read the image file...
|
||||
return (await fs.readFile(where)).toString('base64');
|
||||
return (await hostUtils.readFromBoot(where)).toString('base64');
|
||||
}
|
||||
|
||||
// Write a splash image provided as a base64 string
|
||||
|
@ -1,10 +1,9 @@
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as _ from 'lodash';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as constants from '../lib/constants';
|
||||
import { writeAndSyncFile } from '../lib/fs-utils';
|
||||
import * as hostUtils from '../lib/host-utils';
|
||||
import * as osRelease from '../lib/os-release';
|
||||
|
||||
import log from '../lib/supervisor-console';
|
||||
@ -87,10 +86,8 @@ export default class ConfigJsonConfigBackend {
|
||||
}
|
||||
|
||||
private async write(): Promise<void> {
|
||||
// We use writeAndSyncFile since /mnt/boot partition is a vfat
|
||||
// filesystem which dows not provide atomic file renames. The best
|
||||
// course of action on that case is to write and sync as soon as possible
|
||||
return writeAndSyncFile(
|
||||
// writeToBoot uses fatrw to safely write to the boot partition
|
||||
return hostUtils.writeToBoot(
|
||||
await this.pathOnHost(),
|
||||
JSON.stringify(this.cache),
|
||||
);
|
||||
@ -98,7 +95,7 @@ export default class ConfigJsonConfigBackend {
|
||||
|
||||
private async read(): Promise<string> {
|
||||
const filename = await this.pathOnHost();
|
||||
return JSON.parse(await fs.readFile(filename, 'utf-8'));
|
||||
return JSON.parse(await hostUtils.readFromBoot(filename, 'utf-8'));
|
||||
}
|
||||
|
||||
private async resolveConfigPath(): Promise<string> {
|
||||
|
@ -10,7 +10,7 @@ import * as constants from './lib/constants';
|
||||
import * as dbus from './lib/dbus';
|
||||
import { ENOENT, InternalInconsistencyError } from './lib/errors';
|
||||
import { mkdirp, unlinkAll } from './lib/fs-utils';
|
||||
import { writeToBoot } from './lib/host-utils';
|
||||
import { writeToBoot, readFromBoot } from './lib/host-utils';
|
||||
import * as updateLock from './lib/update-lock';
|
||||
|
||||
const redsocksHeader = stripIndent`
|
||||
@ -66,7 +66,7 @@ async function readProxy(): Promise<ProxyConfig | undefined> {
|
||||
const conf: ProxyConfig = {};
|
||||
let redsocksConf: string;
|
||||
try {
|
||||
redsocksConf = await fs.readFile(redsocksConfPath, 'utf-8');
|
||||
redsocksConf = await readFromBoot(redsocksConfPath, 'utf-8');
|
||||
} catch (e) {
|
||||
if (!ENOENT(e)) {
|
||||
throw e;
|
||||
@ -91,8 +91,7 @@ async function readProxy(): Promise<ProxyConfig | undefined> {
|
||||
}
|
||||
|
||||
try {
|
||||
const noProxy = await fs
|
||||
.readFile(noProxyPath, 'utf-8')
|
||||
const noProxy = await readFromBoot(noProxyPath, 'utf-8')
|
||||
// Prevent empty newline from being reported as a noProxy address
|
||||
.then((addrs) => addrs.split('\n').filter((addr) => addr !== ''));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user