Skip to content
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

fs: default tjs.open() mode parameter to 0666 #297

Merged
merged 2 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions docs/txikijs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ declare namespace tjs {
function lchown(path: string, owner: number, group: number): Promise<void>;

/**
* Opens the file at the given path. Opening modes:
* Opens the file at the given path. Opening flags:
*
* - r: open for reading
* - w: open for writing, truncating the file if it exists
Expand All @@ -563,9 +563,10 @@ declare namespace tjs {
* const f = await tjs.open('file.txt', 'r');
* ```
* @param path The path to the file to be opened.
* @param mode Mode in which to open the file.
* @param flags Flags with which to open the file.
* @param mode File mode bits applied if the file is created. Defaults to `0o666`.
*/
function open(path: string, mode: string): Promise<FileHandle>;
function open(path: string, flags: string, mode?: number): Promise<FileHandle>;

/**
* Removes the directory at the given path.
Expand All @@ -578,7 +579,7 @@ declare namespace tjs {
* Create a directory at the given path.
*
* @param path The path to of the directory to be created.
* @param mode The file mode for the new directory.
* @param mode The file mode for the new directory. Defaults to `0o777`.
*/
function mkdir(path: string, mode?: number): Promise<void>;

Expand Down
2 changes: 1 addition & 1 deletion src/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ static JSValue tjs_fs_open(JSContext *ctx, JSValueConst this_val, int argc, JSVa
flags = js__uv_open_flags(strflags, len);
JS_FreeCString(ctx, strflags);

mode = 0;
mode = 0666;
if (!JS_IsUndefined(argv[2]) && JS_ToInt32(ctx, &mode, argv[2])) {
JS_FreeCString(ctx, path);
return JS_EXCEPTION;
Expand Down