fix(adb): close writable stream when closing AdbDaemonTransport

This commit is contained in:
Simon Chan 2023-08-15 15:25:47 +08:00
parent 637d1f9bf8
commit e185d6a7c6
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
3 changed files with 28 additions and 6 deletions

View file

@ -285,7 +285,7 @@ Creates an `AdbSync` client. The client can send multiple command in sequence, a
public async lstat(path: string): Promise<AdbSyncStat>;
```
Gets the information of a file or folder. If path is a symbolic link, the returned information is about the link itself.
Gets the information of a file or folder. If `path` points to a symbolic link, the returned information is about the link itself.
This uses the `STAT` or `LST2` (when supported) sync commands, notice that despite the name of `STAT`, it doesn't resolve symbolic links.
@ -297,7 +297,7 @@ Same as the [`lstat`](https://linux.die.net/man/2/lstat) system call in Linux.
public async stat(path: string): Promise<AdbSyncStat>;
```
Similar to `lstat`, but if path is a symbolic link, the information is about the file it refers to.
Gets the information of a file or folder. If `path` points to a symbolic link, it will be resolved and the returned information is about the target.
Uses the `STA2` sync command, which requires the `stat_v2` feature flag. Will throw an error if device doesn't support that.
@ -309,7 +309,9 @@ Same as the `stat` system call in Linux.
public async isDirectory(path: string): Promise<boolean>
```
Uses `lstat` method to check if the given path is a directory.
Checks if `path` is a directory, or a symbolic link to a directory.
This uses `lstat` internally, thus works on all Android versions.
#### `opendir`

View file

@ -86,18 +86,33 @@ export class AdbSync extends AutoDisposable {
!this.fixedPushMkdir;
}
/**
* Gets information of a file or folder.
*
* If `path` points to a symbolic link, the returned information is about the link itself (with `type` being `LinuxFileType.Link`).
*/
async lstat(path: string): Promise<AdbSyncStat> {
return await adbSyncLstat(this._socket, path, this.supportsStat);
return await adbSyncLstat(this._socket, path, this.#supportsStat);
}
/**
* Gets the information of a file or folder.
*
* If `path` points to a symbolic link, it will be resolved and the returned information is about the target (with `type` being `LinuxFileType.File` or `LinuxFileType.Directory`).
*/
async stat(path: string) {
if (!this.supportsStat) {
if (!this.#supportsStat) {
throw new Error("Not supported");
}
return await adbSyncStat(this._socket, path);
}
/**
* Checks if `path` is a directory, or a symbolic link to a directory.
*
* This uses `lstat` internally, thus works on all Android versions.
*/
async isDirectory(path: string): Promise<boolean> {
try {
await this.lstat(path + "/");

View file

@ -305,8 +305,13 @@ export class AdbPacketDispatcher implements Closeable {
// It's possible that we haven't received all `CLSE` confirm packets,
// but it doesn't matter, the next connection can cope with them.
this.#closed = true;
this.#readAbortController.abort();
if (this.options.preserveConnection ?? false) {
this.#writer.releaseLock();
} else {
await this.#writer.close();
}
// `pipe().then()` will call `dispose`
}