Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kkebo opened this issue Oct 23, 2024 · 3 comments
Closed

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

kkebo opened this issue Oct 23, 2024 · 3 comments

Comments

@kkebo
Copy link
Contributor

kkebo commented Oct 23, 2024

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
@ahoppen
Copy link
Member

ahoppen commented Oct 23, 2024

Synced to Apple’s issue tracker as rdar://138492445

@macshome
Copy link
Contributor

macshome commented Oct 25, 2024

I've got a simple fix for this, just trying to find a way to add test coverage for it. As it stands this particular code path wasn't covered to begin with and it would be nice to do it now.

I also don't know what I should do about Windows support...

macshome added a commit to macshome/swift-format that referenced this issue Oct 25, 2024
Added an additional check that tests to see if the working directory is root.
swiftlang#862
ahoppen pushed a commit to ahoppen/swift-format that referenced this issue Dec 4, 2024
Added an additional check that tests to see if the working directory is root.
swiftlang#862
ahoppen pushed a commit to macshome/swift-format that referenced this issue Dec 5, 2024
Added an additional check that tests to see if the working directory is root.
swiftlang#862
ahoppen pushed a commit to macshome/swift-format that referenced this issue Dec 5, 2024
Added an additional check that tests to see if the working directory is root.
swiftlang#862
ahoppen pushed a commit to macshome/swift-format that referenced this issue Dec 5, 2024
Added an additional check that tests to see if the working directory is root.
swiftlang#862
ahoppen pushed a commit to macshome/swift-format that referenced this issue Dec 5, 2024
Added an additional check that tests to see if the working directory is root.
swiftlang#862
@kkebo
Copy link
Contributor Author

kkebo commented Dec 6, 2024

Resolved by #865

@kkebo kkebo closed this as completed Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants