2021-01-11 12:13:41 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
2020-09-27 06:22:32 -04:00
|
|
|
import { assertEquals, unitTest } from "./test_util.ts";
|
2020-06-21 09:29:44 -04:00
|
|
|
|
2020-06-26 08:36:35 -04:00
|
|
|
unitTest(
|
|
|
|
{ perms: { read: true, write: true } },
|
|
|
|
function fdatasyncSyncSuccess(): void {
|
|
|
|
const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
|
|
|
|
const file = Deno.openSync(filename, {
|
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const data = new Uint8Array(64);
|
|
|
|
Deno.writeSync(file.rid, data);
|
|
|
|
Deno.fdatasyncSync(file.rid);
|
|
|
|
assertEquals(Deno.readFileSync(filename), data);
|
|
|
|
Deno.close(file.rid);
|
|
|
|
Deno.removeSync(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-26 08:36:35 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
unitTest(
|
|
|
|
{ perms: { read: true, write: true } },
|
|
|
|
async function fdatasyncSuccess(): Promise<void> {
|
|
|
|
const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
|
|
|
|
const file = await Deno.open(filename, {
|
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const data = new Uint8Array(64);
|
|
|
|
await Deno.write(file.rid, data);
|
|
|
|
await Deno.fdatasync(file.rid);
|
|
|
|
assertEquals(await Deno.readFile(filename), data);
|
|
|
|
Deno.close(file.rid);
|
|
|
|
await Deno.remove(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-26 08:36:35 -04:00
|
|
|
);
|
|
|
|
|
2020-06-21 09:29:44 -04:00
|
|
|
unitTest(
|
|
|
|
{ perms: { read: true, write: true } },
|
|
|
|
function fsyncSyncSuccess(): void {
|
|
|
|
const filename = Deno.makeTempDirSync() + "/test_fsyncSync.txt";
|
|
|
|
const file = Deno.openSync(filename, {
|
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const size = 64;
|
|
|
|
Deno.ftruncateSync(file.rid, size);
|
|
|
|
Deno.fsyncSync(file.rid);
|
|
|
|
assertEquals(Deno.statSync(filename).size, size);
|
|
|
|
Deno.close(file.rid);
|
|
|
|
Deno.removeSync(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-21 09:29:44 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
unitTest(
|
|
|
|
{ perms: { read: true, write: true } },
|
|
|
|
async function fsyncSuccess(): Promise<void> {
|
|
|
|
const filename = (await Deno.makeTempDir()) + "/test_fsync.txt";
|
|
|
|
const file = await Deno.open(filename, {
|
|
|
|
read: true,
|
|
|
|
write: true,
|
|
|
|
create: true,
|
|
|
|
});
|
|
|
|
const size = 64;
|
|
|
|
await Deno.ftruncate(file.rid, size);
|
|
|
|
await Deno.fsync(file.rid);
|
|
|
|
assertEquals((await Deno.stat(filename)).size, size);
|
|
|
|
Deno.close(file.rid);
|
|
|
|
await Deno.remove(filename);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-06-21 09:29:44 -04:00
|
|
|
);
|