-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature: creating a directory tree #1367
base: horizon
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
({ | ||
requires: [], | ||
requires: [ | ||
{ "import-type": "builtin", name: "string-dict" }, | ||
], | ||
provides: { | ||
values: { | ||
"open-input-file": "tany", | ||
|
@@ -13,11 +15,12 @@ | |
"close-output-file": "tany", | ||
"close-input-file": "tany", | ||
"create-dir": "tany", | ||
"create-dir-tree": "tany", | ||
"list-files": "tany" | ||
} | ||
}, | ||
nativeRequires: ["fs"], | ||
theModule: function(RUNTIME, NAMESPACE, uri, fs) { | ||
theModule: function(RUNTIME, NAMESPACE, uri, SD, fs) { | ||
function InputFile(name) { | ||
this.name = name; | ||
this.fd = fs.openSync(name, "r"); | ||
|
@@ -27,6 +30,17 @@ | |
this.name = name; | ||
this.fd = fs.openSync(name, (append ? "a" : "w")); | ||
} | ||
var checkISD = RUNTIME.getField(SD, "internal").checkISD; | ||
var isISD = RUNTIME.getField(SD, "internal").isISD; | ||
function makeDirs(baseDir, tree) { | ||
if (!fs.existsSync(baseDir)) fs.mkdirSync(baseDir); | ||
if (isISD(tree)) { | ||
RUNTIME.ffi.toArray(RUNTIME.getField(tree, "keys-list").app()).forEach(function(sub) { | ||
var kid = RUNTIME.getColonField(tree, "get-value").full_meth(tree, sub); | ||
makeDirs(baseDir + "/" + sub, kid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be more judicious about using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't tell, tbh: https://nodejs.org/docs/latest/api/fs.html#fsmkdirpath-options-callback gives an example of calling |
||
}); | ||
} | ||
} | ||
|
||
var vals = { | ||
"open-input-file": RUNTIME.makeFunction(function(filename) { | ||
|
@@ -169,6 +183,13 @@ | |
fs.mkdirSync(directory); | ||
return true; | ||
}, "create-dir"), | ||
"create-dir-tree": RUNTIME.makeFunction(function(baseDir, subtree) { | ||
RUNTIME.ffi.checkArity(2, arguments, "create-dir-tree", false); | ||
RUNTIME.checkString(baseDir); | ||
checkISD(subtree); | ||
makeDirs(baseDir, subtree); | ||
return true; | ||
}, "create-dir-tree"), | ||
"list-files": RUNTIME.makeFunction(function(directory) { | ||
RUNTIME.ffi.checkArity(1, arguments, "list-files", false); | ||
RUNTIME.checkString(directory); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth a comment that this won't stack capture because of what we know about
immutable-string-dict
'sget-value
method being flat? Like if this was changed to a generic.get-value
dictionary interface, this wouldn't be safe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, possibly