Skip to content

Linux: cd and find commands fail when a colon is in the directory or file name #4889

Closed

Description

@OOBF

The /sys and /proc directories have sub-directories with colons in the names. Commands like cd and find fail when trying to access directories with ':'.

PS /> cd /sys/devices/pci0000:00/
cd : Cannot find drive. A drive with the name 'sys/devices/pci0000' does not exist.
At line:1 char:1

  • cd /sys/devices/pci0000:00/
  •   + CategoryInfo          : ObjectNotFound: (sys/devices/pci0000:String) [Set-Location], DriveNotFoundException
      + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
    
    
    
    

PS /> find /sys -name ':'
Cannot find drive. A drive with the name '*' does not exist.
At line:1 char:1

  • find /sys -name ':'
  •   + CategoryInfo          : ObjectNotFound: (*:String) [], DriveNotFoundException
      + FullyQualifiedErrorId : DriveNotFound
    
    

The ls command does work.
PS /> ls /sys/devices/pci0000:00/
0000:00:00.0 0000:00:16.0 0000:00:19.0 0000:00:1b.0 0000:00:1c.1 0000:00:1c.3 0000:00:1d.0 0000:00:1f.2 firmware_node power uevent
0000:00:02.0 0000:00:16.3 0000:00:1a.0 0000:00:1c.0 0000:00:1c.2 0000:00:1c.5 0000:00:1f.0 0000:00:1f.3 pci_bus SMO8800:00


Expected behavior

For files and directories with ':' to be processed correctly, and not as drive names.

Actual behavior


Environment data

Name Value


PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.7
OS Linux 4.4.0-92-generic #115-Ubuntu SMP Thu Aug 10 09:04:33 UTC 2017
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Activity

  1. markekraus commented on Sep 21, 2017

    @markekraus
    Contributor

    Dupe of #3931

  2. BrucePay commented on Sep 21, 2017

    @BrucePay
    Collaborator

    This is not quite a dup of 3931 as it's not exclusively about wildcard expansion and quoting. The command cd /sys/devices/pci0000:00/ should work but it fails because we're treating everything before the colon as a drive name. To fix this, we should probably restrict the set of characters allowed in drive names to be alphanumeric (a breaking change but necessary I think for *nix platforms). Also, the default drive for the file system on *nix is '/' which can't actually be used e.g. ls /: doesn't work. We should change it to be a "real" drive name like root: or some such.

  3. added
    WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
    Issue-BugIssue has been identified as a bug in the product
    on Sep 21, 2017
  4. markekraus commented on Sep 21, 2017

    @markekraus
    Contributor

    Bruce Payette (@BrucePay) is the second example find /sys -name ':' not the same as #4870 and #3931? I missed that the first example was using the cd alias.

  5. BrucePay commented on Sep 21, 2017

    @BrucePay
    Collaborator

    Mark Kraus (@markekraus) Yes the second example is the same as 3931.

  6. lzybkr commented on Sep 21, 2017

    @lzybkr
    Contributor

    Bruce Payette (@BrucePay) - does restricting characters in the drive name? Consider:

    jason@jason:/sys/devices $ cd pci0000:00
    

    In other words - I thought parsing out the drive name happened early in path parsing before trying to resolve the filename portion of the path.

  7. added this to the milestone on Sep 21, 2017
  8. BrucePay commented on Sep 21, 2017

    @BrucePay
    Collaborator

    The drive name is extracted first in order to determine what provider to pass the remainder of the string to. Based on the cd example above, it appears that the code just scans the string until it hits a colon. Restricting the drive name to alphanumerics would cover a lot of cases (e.g. the cd above) but not your specific one. Prefixing with ./ is one workaround e.g. cd ./pci0000:00 or you could specify the actual drive cd root:pci0000:00 (assuming we pre-created a drive "root" of the file system instead of '/' which can't actually be used.) Note: New-PSDrive won't let you create a drive with any of ; ~ / \ . : in the name but we apparently aren't universal in our checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugIssue has been identified as a bug in the productWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions