Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit e185d6a7 authored by Simon Chan's avatar Simon Chan
Browse files

fix(adb): close writable stream when closing AdbDaemonTransport

parent 637d1f9b
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -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`

+17 −2
Original line number Diff line number Diff line
@@ -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 + "/");
+6 −1
Original line number Diff line number Diff line
@@ -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`
    }