@zenfs/core
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -96,2 +96,20 @@ import { checkOptions, isBackend, isBackendConfig } from './backends/backend.js'; | ||
config.syncImmediately = !configuration.onlySyncOnClose; | ||
if (configuration.mounts) { | ||
const toMount = []; | ||
let unmountRoot = 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 (isBackendConfig(mountConfig)) { | ||
mountConfig.disableAsyncCache ?? (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false); | ||
} | ||
if (point == '/') | ||
unmountRoot = true; | ||
toMount.push([point, await resolveMountConfig(mountConfig)]); | ||
} | ||
if (unmountRoot) | ||
fs.umount('/'); | ||
await Promise.all(toMount.map(([point, fs]) => mount(point, fs))); | ||
} | ||
if (configuration.addDevices) { | ||
@@ -103,21 +121,2 @@ const devfs = new DeviceFS(); | ||
} | ||
if (!configuration.mounts) { | ||
return; | ||
} | ||
const toMount = []; | ||
let unmountRoot = 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 (isBackendConfig(mountConfig)) { | ||
mountConfig.disableAsyncCache ?? (mountConfig.disableAsyncCache = configuration.disableAsyncCache || false); | ||
} | ||
if (point == '/') | ||
unmountRoot = true; | ||
toMount.push([point, await resolveMountConfig(mountConfig)]); | ||
} | ||
if (unmountRoot) | ||
fs.umount('/'); | ||
await Promise.all(toMount.map(([point, fs]) => mount(point, fs))); | ||
} |
@@ -25,1 +25,8 @@ export * from './error.js'; | ||
export default fs; | ||
declare global { | ||
/** | ||
* Global FS emulation. Do not use unless absolutely needed. | ||
* @hidden | ||
*/ | ||
var __zenfs__: typeof fs; | ||
} |
@@ -25,1 +25,2 @@ export * from './error.js'; | ||
export default fs; | ||
globalThis.__zenfs__ = fs; |
@@ -10,2 +10,3 @@ import { Stats, type StatsLike } from './stats.js'; | ||
* @internal | ||
* @todo [BREAKING] | ||
*/ | ||
@@ -12,0 +13,0 @@ export declare class Inode implements StatsLike { |
@@ -50,2 +50,3 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
* @internal | ||
* @todo [BREAKING] | ||
*/ | ||
@@ -106,5 +107,20 @@ let Inode = (() => { | ||
if (buffer) { | ||
if (buffer.byteLength < sizeof(Inode)) { | ||
throw new RangeError(`Can not create an inode from a buffer less than ${sizeof(Inode)} bytes`); | ||
const sz_inode = sizeof(Inode); | ||
const oldSize = sz_inode - sizeof('uint64'); | ||
if (buffer.byteLength < oldSize) { | ||
throw new RangeError(`Can not create an inode from a buffer less than ${oldSize} bytes`); | ||
} | ||
// Expand the buffer so it is the right size | ||
if (buffer.byteLength < sz_inode) { | ||
const newBuffer = new Uint32Array(sz_inode); | ||
// Fill the new buffer with current data | ||
newBuffer.set(new Uint32Array(ArrayBuffer.isView(buffer) ? buffer.buffer : buffer)); | ||
/* Add a random ino. | ||
This will be different from the actual one, | ||
but `ino` isn't used anywhere so it should be fine. | ||
*/ | ||
const randomIno = crypto.getRandomValues(new Uint32Array(2)); | ||
newBuffer.set(randomIno, sz_inode - 2); | ||
buffer = newBuffer; | ||
} | ||
deserialize(this, buffer); | ||
@@ -111,0 +127,0 @@ return; |
{ | ||
"name": "@zenfs/core", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A filesystem, anywhere", | ||
@@ -5,0 +5,0 @@ "funding": { |
@@ -199,32 +199,30 @@ import type { Backend, BackendConfiguration, FilesystemOf, SharedConfig } from './backends/backend.js'; | ||
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); | ||
} | ||
} |
@@ -26,1 +26,11 @@ export * from './error.js'; | ||
export default fs; | ||
declare global { | ||
/** | ||
* Global FS emulation. Do not use unless absolutely needed. | ||
* @hidden | ||
*/ | ||
// eslint-disable-next-line no-var | ||
var __zenfs__: typeof fs; | ||
} | ||
globalThis.__zenfs__ = fs; |
@@ -14,2 +14,3 @@ import { deserialize, sizeof, struct, types as t } from 'utilium'; | ||
* @internal | ||
* @todo [BREAKING] | ||
*/ | ||
@@ -20,6 +21,22 @@ @struct() | ||
if (buffer) { | ||
if (buffer.byteLength < sizeof(Inode)) { | ||
throw new RangeError(`Can not create an inode from a buffer less than ${sizeof(Inode)} bytes`); | ||
const sz_inode = sizeof(Inode); | ||
const oldSize = sz_inode - sizeof('uint64'); | ||
if (buffer.byteLength < oldSize) { | ||
throw new RangeError(`Can not create an inode from a buffer less than ${oldSize} bytes`); | ||
} | ||
// Expand the buffer so it is the right size | ||
if (buffer.byteLength < sz_inode) { | ||
const newBuffer = new Uint32Array(sz_inode); | ||
// Fill the new buffer with current data | ||
newBuffer.set(new Uint32Array(ArrayBuffer.isView(buffer) ? buffer.buffer : buffer)); | ||
/* Add a random ino. | ||
This will be different from the actual one, | ||
but `ino` isn't used anywhere so it should be fine. | ||
*/ | ||
const randomIno = crypto.getRandomValues(new Uint32Array(2)); | ||
newBuffer.set(randomIno, sz_inode - 2); | ||
buffer = newBuffer; | ||
} | ||
deserialize(this, buffer); | ||
@@ -26,0 +43,0 @@ return; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
877335
23316