Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Support mkdir at mountpoints (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Apr 8, 2021
1 parent 94cdb69 commit 8756fc1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
36 changes: 36 additions & 0 deletions prelude/bootstrap.js
Expand Up @@ -453,6 +453,8 @@ function payloadFileSync(pointer) {
ancestor.exists = fs.exists;
ancestor.accessSync = fs.accessSync;
ancestor.access = fs.access;
ancestor.mkdirSync = fs.mkdirSync;
ancestor.mkdir = fs.mkdir;

var windows = process.platform === 'win32';

Expand Down Expand Up @@ -1241,6 +1243,40 @@ function payloadFileSync(pointer) {
accessFromSnapshot(path, callback);
};

// ///////////////////////////////////////////////////////////////
// mkdir /////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////

function mkdirFailInSnapshot(path_, cb) {
var cb2 = cb || rethrow;
return cb2(
new Error('Cannot mkdir in a snapshot. Try mountpoints instead.')
);
}

fs.mkdirSync = function mkdirSync(path) {
if (!insideSnapshot(path)) {
return ancestor.mkdirSync.apply(fs, arguments);
}
if (insideMountpoint(path)) {
return ancestor.mkdirSync.apply(fs, translateNth(arguments, 0, path));
}

return mkdirFailInSnapshot(path);
};

fs.mkdir = function mkdir(path) {
if (!insideSnapshot(path)) {
return ancestor.mkdir.apply(fs, arguments);
}
if (insideMountpoint(path)) {
return ancestor.mkdir.apply(fs, translateNth(arguments, 0, path));
}

var callback = dezalgo(maybeCallback(arguments));
mkdirFailInSnapshot(path, callback);
};

// ///////////////////////////////////////////////////////////////
// promises ////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////
Expand Down
27 changes: 27 additions & 0 deletions test/test-1120-mkdir-mountpoints/main.js
@@ -0,0 +1,27 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const assert = require('assert');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

const target = process.argv[2] || 'host';
const input = './test-x-index.js';
const output = './run-time/test-output.exe';

let right;
utils.mkdirp.sync(path.dirname(output));

utils.pkg.sync(['--target', target, '--output', output, input]);

right = utils.spawn.sync('./' + path.basename(output), [], {
cwd: path.dirname(output),
});

assert.strictEqual(right, 'hello.txt\n');

utils.vacuum.sync(path.dirname(output));
18 changes: 18 additions & 0 deletions test/test-1120-mkdir-mountpoints/test-x-index.js
@@ -0,0 +1,18 @@
'use strict';

var fs = require('fs');
var path = require('path');

var myDirectory = path.dirname(process.execPath);

process.pkg.mount(
path.join(__dirname, 'plugins-D-ext'),
path.join(myDirectory, 'plugins-D-ext')
);

fs.mkdirSync('./plugins-D-ext/');
fs.writeFileSync('./plugins-D-ext/hello.txt', 'hello world!');

console.log(
fs.readdirSync(path.join(__dirname, './plugins-D-ext/')).join('\n')
);

0 comments on commit 8756fc1

Please sign in to comment.