mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
revert: Remove deprecations of file sync APIs (#22085)
- `Deno.FsFile.dataSync` -> `Deno.FsFile.syncData` - `Deno.FsFile.dataSyncSync` -> `Deno.FsFile.syncDataSync` Also marks these APIs as unstable
This commit is contained in:
parent
316093fec4
commit
801ed74118
8 changed files with 80 additions and 60 deletions
|
@ -836,7 +836,7 @@ Deno.test(
|
|||
});
|
||||
const data = new Uint8Array(64);
|
||||
file.writeSync(data);
|
||||
file.dataSyncSync();
|
||||
file.syncDataSync();
|
||||
assertEquals(Deno.readFileSync(filename), data);
|
||||
file.close();
|
||||
Deno.removeSync(filename);
|
||||
|
@ -854,7 +854,7 @@ Deno.test(
|
|||
});
|
||||
const data = new Uint8Array(64);
|
||||
await file.write(data);
|
||||
await file.dataSync();
|
||||
await file.syncData();
|
||||
assertEquals(await Deno.readFile(filename), data);
|
||||
file.close();
|
||||
await Deno.remove(filename);
|
||||
|
|
|
@ -19,7 +19,7 @@ Deno.test(
|
|||
const atime = 1000;
|
||||
const mtime = 50000;
|
||||
await Deno.futime(file.rid, atime, mtime);
|
||||
await file.dataSync();
|
||||
await file.syncData();
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
||||
|
@ -40,7 +40,7 @@ Deno.test(
|
|||
const atime = 1000;
|
||||
const mtime = 50000;
|
||||
await file.utime(atime, mtime);
|
||||
await file.dataSync();
|
||||
await file.syncData();
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
||||
|
@ -61,7 +61,7 @@ Deno.test(
|
|||
const atime = 1000;
|
||||
const mtime = 50000;
|
||||
Deno.futimeSync(file.rid, atime, mtime);
|
||||
file.dataSyncSync();
|
||||
file.syncDataSync();
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
||||
|
@ -82,7 +82,7 @@ Deno.test(
|
|||
const atime = 1000;
|
||||
const mtime = 50000;
|
||||
file.utimeSync(atime, mtime);
|
||||
file.dataSyncSync();
|
||||
file.syncDataSync();
|
||||
|
||||
const fileInfo = Deno.statSync(filename);
|
||||
assertEquals(fileInfo.atime, new Date(atime * 1000));
|
||||
|
|
32
cli/tsc/dts/lib.deno.ns.d.ts
vendored
32
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -2182,9 +2182,6 @@ declare namespace Deno {
|
|||
* console.log(await Deno.readTextFile("my_file.txt")); // H
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.FsFile.sync} instead.
|
||||
* {@linkcode Deno.fsync} will be removed in Deno 2.0.
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
export function fsync(rid: number): Promise<void>;
|
||||
|
@ -2204,9 +2201,6 @@ declare namespace Deno {
|
|||
* console.log(Deno.readTextFileSync("my_file.txt")); // H
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.FsFile.syncSync} instead.
|
||||
* {@linkcode Deno.fsyncSync} will be removed in Deno 2.0.
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
export function fsyncSync(rid: number): void;
|
||||
|
@ -2223,9 +2217,6 @@ declare namespace Deno {
|
|||
* console.log(await Deno.readTextFile("my_file.txt")); // Hello World
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.FsFile.dataSync} instead.
|
||||
* {@linkcode Deno.fdatasync} will be removed in v2.0.0.
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
export function fdatasync(rid: number): Promise<void>;
|
||||
|
@ -2244,9 +2235,6 @@ declare namespace Deno {
|
|||
* console.log(Deno.readTextFileSync("my_file.txt")); // Hello World
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use {@linkcode Deno.FsFile.dataSyncSync} instead.
|
||||
* {@linkcode Deno.fdatasyncSync} will be removed in v2.0.0.
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
export function fdatasyncSync(rid: number): void;
|
||||
|
@ -2564,7 +2552,8 @@ declare namespace Deno {
|
|||
* ```
|
||||
*/
|
||||
statSync(): FileInfo;
|
||||
/**
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Flushes any pending data and metadata operations of the given file
|
||||
* stream to disk.
|
||||
*
|
||||
|
@ -2582,7 +2571,8 @@ declare namespace Deno {
|
|||
* @category I/O
|
||||
*/
|
||||
sync(): Promise<void>;
|
||||
/**
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Synchronously flushes any pending data and metadata operations of the given
|
||||
* file stream to disk.
|
||||
*
|
||||
|
@ -2600,7 +2590,8 @@ declare namespace Deno {
|
|||
* @category I/O
|
||||
*/
|
||||
syncSync(): void;
|
||||
/**
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Flushes any pending data operations of the given file stream to disk.
|
||||
* ```ts
|
||||
* using file = await Deno.open(
|
||||
|
@ -2608,14 +2599,15 @@ declare namespace Deno {
|
|||
* { read: true, write: true, create: true },
|
||||
* );
|
||||
* await file.write(new TextEncoder().encode("Hello World"));
|
||||
* await file.dataSync();
|
||||
* await file.syncData();
|
||||
* console.log(await Deno.readTextFile("my_file.txt")); // Hello World
|
||||
* ```
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
dataSync(): Promise<void>;
|
||||
/**
|
||||
syncData(): Promise<void>;
|
||||
/** **UNSTABLE**: New API, yet to be vetted.
|
||||
*
|
||||
* Synchronously flushes any pending data operations of the given file stream
|
||||
* to disk.
|
||||
*
|
||||
|
@ -2625,13 +2617,13 @@ declare namespace Deno {
|
|||
* { read: true, write: true, create: true },
|
||||
* );
|
||||
* file.writeSync(new TextEncoder().encode("Hello World"));
|
||||
* file.dataSyncSync();
|
||||
* file.syncDataSync();
|
||||
* console.log(Deno.readTextFileSync("my_file.txt")); // Hello World
|
||||
* ```
|
||||
*
|
||||
* @category I/O
|
||||
*/
|
||||
dataSyncSync(): void;
|
||||
syncDataSync(): void;
|
||||
/**
|
||||
* Changes the access (`atime`) and modification (`mtime`) times of the
|
||||
* file stream resource. Given times are either in seconds (UNIX epoch
|
||||
|
|
|
@ -15,12 +15,16 @@ const {
|
|||
op_fs_cwd,
|
||||
op_fs_fdatasync_async,
|
||||
op_fs_fdatasync_sync,
|
||||
op_fs_fdatasync_async_unstable,
|
||||
op_fs_fdatasync_sync_unstable,
|
||||
op_fs_flock_async,
|
||||
op_fs_flock_sync,
|
||||
op_fs_fstat_async,
|
||||
op_fs_fstat_sync,
|
||||
op_fs_fsync_async,
|
||||
op_fs_fsync_sync,
|
||||
op_fs_fsync_async_unstable,
|
||||
op_fs_fsync_sync_unstable,
|
||||
op_fs_ftruncate_async,
|
||||
op_fs_ftruncate_sync,
|
||||
op_fs_funlock_async,
|
||||
|
@ -558,20 +562,10 @@ async function symlink(
|
|||
}
|
||||
|
||||
function fdatasyncSync(rid) {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.fdatasyncSync()",
|
||||
new Error().stack,
|
||||
"Use `file.dataSyncSync()` instead.",
|
||||
);
|
||||
op_fs_fdatasync_sync(rid);
|
||||
}
|
||||
|
||||
async function fdatasync(rid) {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.fdatasync()",
|
||||
new Error().stack,
|
||||
"Use `await file.dataSync()` instead.",
|
||||
);
|
||||
await op_fs_fdatasync_async(rid);
|
||||
}
|
||||
|
||||
|
@ -718,12 +712,12 @@ class FsFile {
|
|||
return fstatSync(this.#rid);
|
||||
}
|
||||
|
||||
async dataSync() {
|
||||
await op_fs_fdatasync_async(this.#rid);
|
||||
async syncData() {
|
||||
await op_fs_fdatasync_async_unstable(this.#rid);
|
||||
}
|
||||
|
||||
dataSyncSync() {
|
||||
op_fs_fdatasync_sync(this.#rid);
|
||||
syncDataSync() {
|
||||
op_fs_fdatasync_sync_unstable(this.#rid);
|
||||
}
|
||||
|
||||
close() {
|
||||
|
@ -745,11 +739,11 @@ class FsFile {
|
|||
}
|
||||
|
||||
async sync() {
|
||||
await op_fs_fsync_async(this.#rid);
|
||||
await op_fs_fsync_async_unstable(this.#rid);
|
||||
}
|
||||
|
||||
syncSync() {
|
||||
op_fs_fsync_sync(this.#rid);
|
||||
op_fs_fsync_sync_unstable(this.#rid);
|
||||
}
|
||||
|
||||
async utime(atime, mtime) {
|
||||
|
|
|
@ -130,8 +130,12 @@ deno_core::extension!(deno_fs,
|
|||
op_fs_seek_async,
|
||||
op_fs_fdatasync_sync,
|
||||
op_fs_fdatasync_async,
|
||||
op_fs_fdatasync_sync_unstable,
|
||||
op_fs_fdatasync_async_unstable,
|
||||
op_fs_fsync_sync,
|
||||
op_fs_fsync_async,
|
||||
op_fs_fsync_sync_unstable,
|
||||
op_fs_fsync_async_unstable,
|
||||
op_fs_fstat_sync,
|
||||
op_fs_fstat_async,
|
||||
op_fs_flock_sync,
|
||||
|
|
|
@ -1349,6 +1349,17 @@ pub fn op_fs_fdatasync_sync(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_fdatasync_sync_unstable(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
check_unstable(state, "Deno.FsFile.syncDataSync");
|
||||
let file = FileResource::get_file(state, rid)?;
|
||||
file.datasync_sync()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_fdatasync_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
|
@ -1359,6 +1370,17 @@ pub async fn op_fs_fdatasync_async(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_fdatasync_async_unstable(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
check_unstable(&state.borrow(), "Deno.FsFile.syncData");
|
||||
let file = FileResource::get_file(&state.borrow(), rid)?;
|
||||
file.datasync_async().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_fsync_sync(
|
||||
state: &mut OpState,
|
||||
|
@ -1369,6 +1391,17 @@ pub fn op_fs_fsync_sync(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_fsync_sync_unstable(
|
||||
state: &mut OpState,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
check_unstable(state, "Deno.FsFile.syncSync");
|
||||
let file = FileResource::get_file(state, rid)?;
|
||||
file.sync_sync()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_fsync_async(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
|
@ -1379,6 +1412,17 @@ pub async fn op_fs_fsync_async(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(async)]
|
||||
pub async fn op_fs_fsync_async_unstable(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
#[smi] rid: ResourceId,
|
||||
) -> Result<(), AnyError> {
|
||||
check_unstable(&state.borrow(), "Deno.FsFile.sync");
|
||||
let file = FileResource::get_file(&state.borrow(), rid)?;
|
||||
file.sync_async().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[op2(fast)]
|
||||
pub fn op_fs_fstat_sync(
|
||||
state: &mut OpState,
|
||||
|
|
|
@ -10,9 +10,9 @@ export function fdatasync(
|
|||
fd: number,
|
||||
callback: CallbackWithError,
|
||||
) {
|
||||
new FsFile(fd).dataSync().then(() => callback(null), callback);
|
||||
new FsFile(fd).syncData().then(() => callback(null), callback);
|
||||
}
|
||||
|
||||
export function fdatasyncSync(fd: number) {
|
||||
new FsFile(fd).dataSyncSync();
|
||||
new FsFile(fd).syncDataSync();
|
||||
}
|
||||
|
|
|
@ -225,22 +225,8 @@ const denoNs = {
|
|||
);
|
||||
return fs.fstat(rid);
|
||||
},
|
||||
fsyncSync(rid) {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.fsyncSync()",
|
||||
new Error().stack,
|
||||
"Use `Deno.FsFile.syncSync()` instead.",
|
||||
);
|
||||
fs.fsyncSync(rid);
|
||||
},
|
||||
async fsync(rid) {
|
||||
internals.warnOnDeprecatedApi(
|
||||
"Deno.fsync()",
|
||||
new Error().stack,
|
||||
"Use `Deno.FsFile.sync()` instead.",
|
||||
);
|
||||
await fs.fsync(rid);
|
||||
},
|
||||
fsyncSync: fs.fsyncSync,
|
||||
fsync: fs.fsync,
|
||||
fdatasyncSync: fs.fdatasyncSync,
|
||||
fdatasync: fs.fdatasync,
|
||||
symlink: fs.symlink,
|
||||
|
|
Loading…
Reference in a new issue