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

Implement _lstatFile on Windows #2015

Merged
merged 1 commit into from
Mar 21, 2019

Conversation

gmittert
Copy link
Contributor

@gmittert gmittert commented Mar 15, 2019

Windows doesn't have lstat, but it still can be implemented. This should
help remove some of the Windows specific codepaths.

This is based off the lstat in llbuild

Also depends on swiftlang/swift#23342

@gmittert
Copy link
Contributor Author

@compnerd

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be extremely helpful to me!

@@ -1818,19 +1817,70 @@ open class FileManager : NSObject {
}

var statInfo = stat()
#if os(Windows)
let h = path.withCString(encodedAs: UTF16.self) {
CreateFileW( /*lpFileName=*/$0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Extra whitespace.

if err == ERROR_FILE_NOT_FOUND {
errno = ENOENT
}
throw _NSErrorWithErrno(errno, reading: true, path: path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just replace this with _NSErrorWithWindowsError

// themselves, we say symlinks are regular files
UInt16((info.dwFileAttributes & DWORD(FILE_ATTRIBUTE_REPARSE_POINT)) != 0
? _S_IFREG
: (info.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY)) != 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract the checks into variables please, it makes it easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Windows doesn't have lstat, but it still can be implemented. This should
help remove some of the Windows specific codepaths.
@gmittert gmittert force-pushed the DontFollowSketchyLinks branch from f419d5a to a62b609 Compare March 19, 2019 19:33
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@compnerd
Copy link
Member

@swift-ci please test and merge

1 similar comment
@compnerd
Copy link
Member

@swift-ci please test and merge

@swift-ci swift-ci merged commit a733b6b into swiftlang:master Mar 21, 2019
@gmittert gmittert deleted the DontFollowSketchyLinks branch March 29, 2019 00:31
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

Successfully merging this pull request may close these issues.

3 participants