Skip to content

Commit

Permalink
/dev is now added after other mounts, in case / is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Nov 12, 2024
1 parent 8c1ed21 commit 83e6fca
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { DeviceFS } from './devices.js';
import * as cache from './emulation/cache.js';
import { config } from './emulation/config.js';
import * as fs from './emulation/index.js';
import type { AbsolutePath } from './emulation/path.js';
import { parse, type AbsolutePath } from './emulation/path.js';

Check warning on line 8 in src/config.ts

View workflow job for this annotation

GitHub Actions / CI

'parse' is defined but never used
import { resolveMount } from './emulation/shared.js';

Check warning on line 9 in src/config.ts

View workflow job for this annotation

GitHub Actions / CI

'resolveMount' is defined but never used
import { Errno, ErrnoError } from './error.js';
import { FileSystem } from './filesystem.js';

Expand Down Expand Up @@ -196,34 +197,32 @@ export async function configure<T extends ConfigMounts>(configuration: Partial<C
config.updateOnRead = !configuration.disableUpdateOnRead;
config.syncImmediately = !configuration.onlySyncOnClose;

if (configuration.addDevices) {
const devfs = new DeviceFS();
devfs.addDefaults();
await devfs.ready();
await mount('/dev', devfs);
}
if (configuration.mounts) {
const toMount: [string, FileSystem][] = [];
let unmountRoot = false;

if (!configuration.mounts) {
return;
}
for (const [point, mountConfig] of Object.entries(configuration.mounts)) {
if (!point.startsWith('/')) {
throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
}

const toMount: [string, FileSystem][] = [];
let unmountRoot = false;
if (isBackendConfig(mountConfig)) {
mountConfig.disableAsyncCache ??= configuration.disableAsyncCache || false;
}

for (const [point, mountConfig] of Object.entries(configuration.mounts)) {
if (!point.startsWith('/')) {
throw new ErrnoError(Errno.EINVAL, 'Mount points must have absolute paths');
if (point == '/') unmountRoot = true;
toMount.push([point, await resolveMountConfig(mountConfig)]);
}

if (isBackendConfig(mountConfig)) {
mountConfig.disableAsyncCache ??= configuration.disableAsyncCache || false;
}
if (unmountRoot) fs.umount('/');

if (point == '/') unmountRoot = true;
toMount.push([point, await resolveMountConfig(mountConfig)]);
await Promise.all(toMount.map(([point, fs]) => mount(point, fs)));
}

if (unmountRoot) fs.umount('/');

await Promise.all(toMount.map(([point, fs]) => mount(point, fs)));
if (configuration.addDevices) {
const devfs = new DeviceFS();
devfs.addDefaults();
await devfs.ready();
await mount('/dev', devfs);
}
}

0 comments on commit 83e6fca

Please sign in to comment.