summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/lib.deno.ns.d.ts4
-rw-r--r--cli/js/tests/chmod_test.ts26
-rw-r--r--cli/js/write_file.ts13
3 files changed, 21 insertions, 22 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 33d89190c..4a7609920 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -950,7 +950,7 @@ declare namespace Deno {
*
* For a full description, see [chmod](#chmod)
*
- * NOTE: This API currently has no effect on Windows
+ * NOTE: This API currently throws on Windows
*
* Requires `allow-write` permission. */
export function chmodSync(path: string, mode: number): void;
@@ -978,7 +978,7 @@ declare namespace Deno {
* | 1 | execute only |
* | 0 | no permission |
*
- * NOTE: This API currently has no effect on Windows
+ * NOTE: This API currently throws on Windows
*
* Requires `allow-write` permission. */
export function chmod(path: string, mode: number): Promise<void>;
diff --git a/cli/js/tests/chmod_test.ts b/cli/js/tests/chmod_test.ts
index 4720fa784..e71e0bf26 100644
--- a/cli/js/tests/chmod_test.ts
+++ b/cli/js/tests/chmod_test.ts
@@ -1,10 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { unitTest, assert, assertEquals } from "./test_util.ts";
-const isNotWindows = Deno.build.os !== "win";
-
unitTest(
- { perms: { read: true, write: true } },
+ { ignore: Deno.build.os === "win", perms: { read: true, write: true } },
function chmodSyncSuccess(): void {
const enc = new TextEncoder();
const data = enc.encode("Hello");
@@ -12,15 +10,11 @@ unitTest(
const filename = tempDir + "/test.txt";
Deno.writeFileSync(filename, data, { mode: 0o666 });
- // On windows no effect, but should not crash
Deno.chmodSync(filename, 0o777);
- // Check success when not on windows
- if (isNotWindows) {
- const fileInfo = Deno.statSync(filename);
- assert(fileInfo.mode);
- assertEquals(fileInfo.mode & 0o777, 0o777);
- }
+ const fileInfo = Deno.statSync(filename);
+ assert(fileInfo.mode);
+ assertEquals(fileInfo.mode & 0o777, 0o777);
}
);
@@ -79,7 +73,7 @@ unitTest({ perms: { write: false } }, function chmodSyncPerm(): void {
});
unitTest(
- { perms: { read: true, write: true } },
+ { ignore: Deno.build.os === "win", perms: { read: true, write: true } },
async function chmodSuccess(): Promise<void> {
const enc = new TextEncoder();
const data = enc.encode("Hello");
@@ -87,15 +81,11 @@ unitTest(
const filename = tempDir + "/test.txt";
Deno.writeFileSync(filename, data, { mode: 0o666 });
- // On windows no effect, but should not crash
await Deno.chmod(filename, 0o777);
- // Check success when not on windows
- if (isNotWindows) {
- const fileInfo = Deno.statSync(filename);
- assert(fileInfo.mode);
- assertEquals(fileInfo.mode & 0o777, 0o777);
- }
+ const fileInfo = Deno.statSync(filename);
+ assert(fileInfo.mode);
+ assertEquals(fileInfo.mode & 0o777, 0o777);
}
);
diff --git a/cli/js/write_file.ts b/cli/js/write_file.ts
index 5227bfece..ed64141d2 100644
--- a/cli/js/write_file.ts
+++ b/cli/js/write_file.ts
@@ -3,6 +3,7 @@ import { stat, statSync } from "./ops/fs/stat.ts";
import { open, openSync } from "./files.ts";
import { chmod, chmodSync } from "./ops/fs/chmod.ts";
import { writeAll, writeAllSync } from "./buffer.ts";
+import { build } from "./build.ts";
export interface WriteFileOptions {
append?: boolean;
@@ -26,7 +27,11 @@ export function writeFileSync(
const openMode = !!options.append ? "a" : "w";
const file = openSync(path, openMode);
- if (options.mode !== undefined && options.mode !== null) {
+ if (
+ options.mode !== undefined &&
+ options.mode !== null &&
+ build.os !== "win"
+ ) {
chmodSync(path, options.mode);
}
@@ -50,7 +55,11 @@ export async function writeFile(
const openMode = !!options.append ? "a" : "w";
const file = await open(path, openMode);
- if (options.mode !== undefined && options.mode !== null) {
+ if (
+ options.mode !== undefined &&
+ options.mode !== null &&
+ build.os !== "win"
+ ) {
await chmod(path, options.mode);
}