Skip to content

FileIterator returns broken URLs when the working directory is / #862

@kkebo

Description

@kkebo

Description

When you use the -r option and workingDirectory.path is "/", String(path.dropFirst(workingDirectory.path.count + 1)) will remove the first character of the file path, so FileIterator returns broken URLs and swift-format can't read any file.

? String(path.dropFirst(workingDirectory.path.count + 1))

How to reproduce the issue

For instance, on wasm32-unknown-wasi, URL(fileURLWithPath: ".") will be /, so this is the problem.

And also, the issue can be reproducible on normal platforms like this:

$ pwd
/
$ ls -l | grep *.swift
.rw-r--r--. root root  12 B  Thu Oct 24 02:39:39 2024 test.swift                                                                                                     
$ swift format lint -rs .
<unknown>: error: Unable to open est.swift: file is not readable or does not exist

My environment:

  • Linux aarch64
  • Swift 6.0 development snapshot toolchain (6.0-snapshot-2024-10-08)
    Swift version 6.0.3-dev (LLVM 81a2745a5c40b5f, Swift 8f95e04bb5d9d9a)
    Target: aarch64-unknown-linux-gnu
    
  • swift-format bundled with the Swift toolchain

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions