from ._base import Opener
from ._registry import registry


@registry.install
class SSHOpener(Opener):
    protocols = ['ssh']

    @staticmethod
    def open_fs(fs_url, parse_result, writeable, create, cwd):
        from ..sshfs import SSHFS
        ssh_host, _, dir_path = parse_result.resource.partition('/')
        ssh_host, _, ssh_port = ssh_host.partition(':')
        ssh_port = int(ssh_port) if ssh_port.isdigit() else 22
        ssh_fs = SSHFS(
            ssh_host,
            port=ssh_port,
            user=parse_result.username,
            passwd=parse_result.password,
        )
        return ssh_fs.opendir(dir_path) if dir_path else ssh_fs

from ._base import Opener
from ._registry import registry
from ..subfs import ClosingSubFS

@registry.install
class SSHOpener(Opener):
    protocols = ['ssh']

    @staticmethod
    def open_fs(fs_url, parse_result, writeable, create, cwd):
        from ..sshfs import SSHFS
        ssh_host, _, dir_path = parse_result.resource.partition('/')
        ssh_host, _, ssh_port = ssh_host.partition(':')
        ssh_port = int(ssh_port) if ssh_port.isdigit() else 22
        ssh_fs = SSHFS(
            ssh_host,
            port=ssh_port,
            user=parse_result.username,
            passwd=parse_result.password,
        )
        
        if dir_path:
            return ssh_fs.opendir(dir_path, factory=ClosingSubFS)
        else:
            return ssh_fs

Fix SSHOpener to use the new ClosingSubFS
Fix SSHOpener to use the new ClosingSubFS

  from ._base import Opener
  from ._registry import registry
- 
+ from ..subfs import ClosingSubFS
  
  @registry.install
  class SSHOpener(Opener):
      protocols = ['ssh']
  
      @staticmethod
      def open_fs(fs_url, parse_result, writeable, create, cwd):
          from ..sshfs import SSHFS
          ssh_host, _, dir_path = parse_result.resource.partition('/')
          ssh_host, _, ssh_port = ssh_host.partition(':')
          ssh_port = int(ssh_port) if ssh_port.isdigit() else 22
          ssh_fs = SSHFS(
              ssh_host,
              port=ssh_port,
              user=parse_result.username,
              passwd=parse_result.password,
          )
-         return ssh_fs.opendir(dir_path) if dir_path else ssh_fs
+         
+         if dir_path:
+             return ssh_fs.opendir(dir_path, factory=ClosingSubFS)
+         else:
+             return ssh_fs
  
Fix SSHOpener to use the new ClosingSubFS
## Code Before:
from ._base import Opener
from ._registry import registry


@registry.install
class SSHOpener(Opener):
    protocols = ['ssh']

    @staticmethod
    def open_fs(fs_url, parse_result, writeable, create, cwd):
        from ..sshfs import SSHFS
        ssh_host, _, dir_path = parse_result.resource.partition('/')
        ssh_host, _, ssh_port = ssh_host.partition(':')
        ssh_port = int(ssh_port) if ssh_port.isdigit() else 22
        ssh_fs = SSHFS(
            ssh_host,
            port=ssh_port,
            user=parse_result.username,
            passwd=parse_result.password,
        )
        return ssh_fs.opendir(dir_path) if dir_path else ssh_fs

## Instruction:
Fix SSHOpener to use the new ClosingSubFS
## Code After:
from ._base import Opener
from ._registry import registry
from ..subfs import ClosingSubFS

@registry.install
class SSHOpener(Opener):
    protocols = ['ssh']

    @staticmethod
    def open_fs(fs_url, parse_result, writeable, create, cwd):
        from ..sshfs import SSHFS
        ssh_host, _, dir_path = parse_result.resource.partition('/')
        ssh_host, _, ssh_port = ssh_host.partition(':')
        ssh_port = int(ssh_port) if ssh_port.isdigit() else 22
        ssh_fs = SSHFS(
            ssh_host,
            port=ssh_port,
            user=parse_result.username,
            passwd=parse_result.password,
        )
        
        if dir_path:
            return ssh_fs.opendir(dir_path, factory=ClosingSubFS)
        else:
            return ssh_fs
