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

Support mkdir at mountpoints #1120

Merged
merged 5 commits into from
Apr 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions prelude/bootstrap.js
Original file line number Diff line number Diff line change
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 mkdirInSnapshot(path_, cb) {
var cb2 = cb || rethrow;
return cb2(
new Error('Cannot mkdir in a snapshot. Try mountpoints instead.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better error for here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would instead change the name of the method in something more user friendly, something like mkdirThrowInSnapshot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with mkdirFailInSnapshot because it doesn't throw if a callback is provided to the async method, but it still fails.

);
}

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 mkdirInSnapshot(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));
mkdirInSnapshot(path, callback);
};

// ///////////////////////////////////////////////////////////////
// promises ////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////
Expand Down