2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-06-24 18:57:08 -04:00
|
|
|
import {
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals,
|
2021-09-22 09:21:11 -04:00
|
|
|
assertRejects,
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows,
|
2021-05-31 14:05:57 -04:00
|
|
|
pathToAbsoluteFileUrl,
|
2020-06-24 18:57:08 -04:00
|
|
|
} from "./test_util.ts";
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function futimeSyncSuccess() {
|
2020-08-31 14:29:43 -04:00
|
|
|
const testDir = await Deno.makeTempDir();
|
|
|
|
const filename = testDir + "/file.txt";
|
2024-01-21 18:20:59 -05:00
|
|
|
using file = await Deno.open(filename, {
|
2020-08-31 14:29:43 -04:00
|
|
|
create: true,
|
|
|
|
write: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
await Deno.futime(file.rid, atime, mtime);
|
2024-01-23 18:31:52 -05:00
|
|
|
await file.dataSync();
|
2020-08-31 14:29:43 -04:00
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
2020-08-31 14:29:43 -04:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2024-01-24 11:26:49 -05:00
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true, write: true } },
|
|
|
|
async function fsFileUtimeSyncSuccess() {
|
|
|
|
const testDir = await Deno.makeTempDir();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
using file = await Deno.open(filename, {
|
|
|
|
create: true,
|
|
|
|
write: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
await file.utime(atime, mtime);
|
|
|
|
await file.dataSync();
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function futimeSyncSuccess() {
|
2020-08-31 14:29:43 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
2024-01-21 18:20:59 -05:00
|
|
|
using file = Deno.openSync(filename, {
|
2020-08-31 14:29:43 -04:00
|
|
|
create: true,
|
|
|
|
write: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
Deno.futimeSync(file.rid, atime, mtime);
|
2024-01-23 18:31:52 -05:00
|
|
|
file.dataSyncSync();
|
2020-08-31 14:29:43 -04:00
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
2020-08-31 14:29:43 -04:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2024-01-24 11:26:49 -05:00
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true, write: true } },
|
|
|
|
function futimeSyncSuccess() {
|
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
using file = Deno.openSync(filename, {
|
|
|
|
create: true,
|
|
|
|
write: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
file.utimeSync(atime, mtime);
|
|
|
|
file.dataSyncSync();
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncFileSuccess() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
2020-03-28 13:03:49 -04:00
|
|
|
mode: 0o666,
|
2020-03-04 11:31:14 -05:00
|
|
|
});
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
Deno.utimeSync(filename, atime, mtime);
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
const fileInfo = Deno.statSync(filename);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncUrlSuccess() {
|
2021-05-31 14:05:57 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
|
|
mode: 0o666,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
Deno.utimeSync(pathToAbsoluteFileUrl(filename), atime, mtime);
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncDirectorySuccess() {
|
2019-05-01 05:08:12 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
Deno.utimeSync(testDir, atime, mtime);
|
|
|
|
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(dirInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(dirInfo.mtime, new Date(mtime * 1000));
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2019-05-01 05:08:12 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncDateSuccess() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2020-04-27 14:09:56 -04:00
|
|
|
const atime = new Date(1000_000);
|
|
|
|
const mtime = new Date(50000_000);
|
|
|
|
Deno.utimeSync(testDir, atime, mtime);
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
const dirInfo = Deno.statSync(testDir);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(dirInfo.atime, atime);
|
|
|
|
assertEquals(dirInfo.mtime, mtime);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2020-04-03 15:20:40 -04:00
|
|
|
function utimeSyncFileDateSuccess() {
|
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
|
|
mode: 0o666,
|
|
|
|
});
|
|
|
|
const atime = new Date();
|
|
|
|
const mtime = new Date();
|
|
|
|
Deno.utimeSync(filename, atime, mtime);
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.atime, atime);
|
|
|
|
assertEquals(fileInfo.mtime, mtime);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-04-03 15:20:40 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncLargeNumberSuccess() {
|
2019-05-01 05:08:12 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
|
|
|
|
// There are Rust side caps (might be fs relate),
|
|
|
|
// so JUST make them slightly larger than UINT32_MAX.
|
|
|
|
const atime = 0x100000001;
|
|
|
|
const mtime = 0x100000002;
|
|
|
|
Deno.utimeSync(testDir, atime, mtime);
|
|
|
|
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(dirInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(dirInfo.mtime, new Date(mtime * 1000));
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2019-05-01 05:08:12 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncNotFound() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2021-10-11 09:21:18 -04:00
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
Deno.utimeSync("/baddir", atime, mtime);
|
|
|
|
},
|
|
|
|
Deno.errors.NotFound,
|
|
|
|
"utime '/baddir'",
|
|
|
|
);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: false } },
|
2021-08-05 07:08:58 -04:00
|
|
|
function utimeSyncPerm() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
|
2020-06-24 18:57:08 -04:00
|
|
|
assertThrows(() => {
|
2020-03-04 11:31:14 -05:00
|
|
|
Deno.utimeSync("/some_dir", atime, mtime);
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
2019-05-01 05:08:12 -04:00
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeFileSuccess() {
|
2019-05-01 05:08:12 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
2020-03-28 13:03:49 -04:00
|
|
|
mode: 0o666,
|
2019-05-01 05:08:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
await Deno.utime(filename, atime, mtime);
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
2021-05-31 14:05:57 -04:00
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeUrlSuccess() {
|
2021-05-31 14:05:57 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
|
|
mode: 0o666,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
await Deno.utime(pathToAbsoluteFileUrl(filename), atime, mtime);
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
|
|
|
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.mtime, new Date(mtime * 1000));
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2019-05-01 05:08:12 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeDirectorySuccess() {
|
2019-05-01 05:08:12 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
|
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
await Deno.utime(testDir, atime, mtime);
|
|
|
|
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(dirInfo.atime, new Date(atime * 1000));
|
|
|
|
assertEquals(dirInfo.mtime, new Date(mtime * 1000));
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2019-05-01 05:08:12 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeDateSuccess() {
|
2019-05-01 05:08:12 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
|
2020-04-27 14:09:56 -04:00
|
|
|
const atime = new Date(100_000);
|
|
|
|
const mtime = new Date(5000_000);
|
|
|
|
await Deno.utime(testDir, atime, mtime);
|
2019-05-01 05:08:12 -04:00
|
|
|
|
|
|
|
const dirInfo = Deno.statSync(testDir);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(dirInfo.atime, atime);
|
|
|
|
assertEquals(dirInfo.mtime, mtime);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2019-05-01 05:08:12 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeFileDateSuccess() {
|
2020-04-03 15:20:40 -04:00
|
|
|
const testDir = Deno.makeTempDirSync();
|
|
|
|
const filename = testDir + "/file.txt";
|
|
|
|
Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
|
|
|
|
mode: 0o666,
|
|
|
|
});
|
|
|
|
|
|
|
|
const atime = new Date();
|
|
|
|
const mtime = new Date();
|
|
|
|
await Deno.utime(filename, atime, mtime);
|
|
|
|
|
|
|
|
const fileInfo = Deno.statSync(filename);
|
2020-09-01 10:03:07 -04:00
|
|
|
assertEquals(fileInfo.atime, atime);
|
|
|
|
assertEquals(fileInfo.mtime, mtime);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-04-03 15:20:40 -04:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: true } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeNotFound() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
|
2021-10-11 09:21:18 -04:00
|
|
|
await assertRejects(
|
|
|
|
async () => {
|
|
|
|
await Deno.utime("/baddir", atime, mtime);
|
|
|
|
},
|
|
|
|
Deno.errors.NotFound,
|
|
|
|
"utime '/baddir'",
|
|
|
|
);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(
|
2021-09-22 19:50:50 -04:00
|
|
|
{ permissions: { read: true, write: false } },
|
2021-08-05 07:08:58 -04:00
|
|
|
async function utimeSyncPerm() {
|
2020-03-04 11:31:14 -05:00
|
|
|
const atime = 1000;
|
|
|
|
const mtime = 50000;
|
|
|
|
|
2021-09-22 09:21:11 -04:00
|
|
|
await assertRejects(async () => {
|
2020-03-04 11:31:14 -05:00
|
|
|
await Deno.utime("/some_dir", atime, mtime);
|
2020-06-24 18:57:08 -04:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2020-07-14 15:24:17 -04:00
|
|
|
},
|
2020-03-04 11:31:14 -05:00
|
|
|
);
|