fix(runtime/fs): preserve permissions in copyFileSync for macOS (#17412)

Fixes https://github.com/denoland/deno/issues/16921
This commit is contained in:
Divy Srivastava 2023-01-14 05:45:30 -08:00 committed by GitHub
parent 68782346d0
commit ae2981d7ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 2 deletions

View file

@ -209,3 +209,30 @@ Deno.test(
}, Deno.errors.PermissionDenied);
},
);
function copyFileSyncMode(content: string): void {
const tempDir = Deno.makeTempDirSync();
const fromFilename = tempDir + "/from.txt";
const toFilename = tempDir + "/to.txt";
Deno.writeTextFileSync(fromFilename, content);
Deno.chmodSync(fromFilename, 0o100755);
Deno.copyFileSync(fromFilename, toFilename);
const toStat = Deno.statSync(toFilename);
assertEquals(toStat.mode!, 0o100755);
}
Deno.test(
{
ignore: Deno.build.os === "windows",
permissions: { read: true, write: true },
},
function copyFileSyncChmod() {
// this Tests different optimization paths on MacOS:
//
// < 128 KB clonefile() w/ fallback to copyfile()
// > 128 KB
copyFileSyncMode("Hello world!");
copyFileSyncMode("Hello world!".repeat(128 * 1024));
},
);