Skip to content

cp, ls and others cannot access file that is actually present (and accessible). #10571

Closed

Description

@bobhy

Describe the bug

Apropos the discussion at the bottom of #10557

If a file path contains glob metachars, you cannot access it from any command that takes arguemnts that are globs (unless you do extra glob quoting).

How to reproduce

Example:

> ls **/*
╭───┬───────┬──────┬──────┬────────────────╮
│ # │ name  │ type │ size │    modified    │
├───┼───────┼──────┼──────┼────────────────┤
│ 0 │ a[b]d │ file │  0 B │ 35 seconds ago │
│ 1 │ foo   │ dir  │  2 B │ a minute ago   │
╰───┴───────┴──────┴──────┴────────────────╯
> glob a[b]d
╭────────────╮
│ empty list │
╰────────────╯
> ucp a[b]d foo
Error: nu::shell::file_not_found

  × File not found
   ╭─[entry #41:1:1]
 1 │ ucp a[b]d foo
   ·     ──┬──
   ·       ╰── file not found
   ╰────

> cp a[b]d foo
Error:   × No matches found
   ╭─[entry #42:1:1]
 1 │ cp a[b]d foo
   ·    ──┬──
   ·      ╰── no matches found
   ╰────

> ls a[b]d
Error:   × No matches found for a[b]d
   ╭─[entry #44:1:1]
 1 │ ls a[b]d
   ·    ──┬──
   ·      ╰── Pattern, file or folder not found
   ╰────
  help: no matches found

The file exists, but cannot be accessed by any of the above command.

You can access it, but need to resort to quoting in the command argument:

> ls a[b]d
Error:   × No matches found for a[b]d
   ╭─[entry #44:1:1]
 1 │ ls a[b]d
   ·    ──┬──
   ·      ╰── Pattern, file or folder not found
   ╰────
  help: no matches found

> ls a[[]b[]]d
╭───┬───────┬──────┬──────┬────────────────╮
│ # │ name  │ type │ size │    modified    │
├───┼───────┼──────┼──────┼────────────────┤
│ 0 │ a[b]d │ file │  0 B │ 14 minutes ago │
╰───┴───────┴──────┴──────┴────────────────╯

Expected behavior

I think user is right to expect ls, cp to be able to access the file whose name is explicitly provided. The path contains unusual, but perfectly legal chars.

Further, the user is not likely to try glob quoting with [] to workaround this issue. S/he is more likely to try string quoting with \ and get frustrated that does not work.

Screenshots

No response

Configuration

key value
version 0.85.1
branch wax_glob2
commit_hash 9ced035
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.70.0 (90c541806 2023-05-31)
rust_channel 1.70.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.70.0 (ec8a8a0ca 2023-04-25)
build_time 2023-10-01 10:13:49 -07:00
build_rust_channel debug
allocator mimalloc
features default, sqlite, trash, which, zip
installed_plugins

Additional context

Note that we have this problem with glob characters that were supported before PR #10557, and with commands that use both the new and the old glob algorithm.

What to do? For all of the commands that take a glob as argument, with the possible exception of glob command, I think the right thing to do is first try the arg as a literal path (e.g stat the arg), only proceed to try it as a glob if the stat fails.

Activity

  1. added
    status:needs-triage
    on Oct 1, 2023
  2. changed the title [-]`cp`, `ls` and others cannot access file that is actually present (and actually ).[/-] [+]`cp`, `ls` and others cannot access file that is actually present (and accessible).[/+] on Oct 1, 2023
  3. added
    A:file-system
    A:glob
    on Oct 2, 2023
  4. added a commit that references this issue on Oct 18, 2023
    09b3dab
  5. added this to the v0.87.0 milestone on Oct 19, 2023
  6. added a commit that references this issue on Oct 20, 2023
    41592b5
  7. added a commit that references this issue on Dec 14, 2023
    7486f38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:file-systemA:globstatus:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions