-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[SR-9979] FileHandle class used to implement FileManager._compareFiles #2029
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
[SR-9979] FileHandle class used to implement FileManager._compareFiles #2029
Conversation
@swift-ci please test |
Thanks for this, I just have a few comments: Since the filenames are already in FSR (File System Representation), converting them back to a I would suggest adding a new For the read loop, I would add another This could make the
|
@spevans Thanks for reviewing my PR Simon. I have updated the code as per your suggestion. Now it is ready for the next round of review. |
Foundation/FileHandle.swift
Outdated
@@ -425,6 +433,15 @@ open class FileHandle : NSObject, NSSecureCoding { | |||
} | |||
} | |||
#endif | |||
|
|||
internal init?(fileSystemRepresentation: UnsafePointer<Int8>, flags: Int32, createMode: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that we should do this. The problem is that on Windows, you need to use UTF16 (or Unicode) for the filenames for the FSR otherwise you will not be able to open all files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The methods _compareFiles()
and contentEquals()
does not support Windows platform, yet. We will cross the bridge when we get to it. As for as this PR concern it seems to me, it is safe to wrap this init
method under #if !os(Windows)
. What do you think @compnerd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SR was filed specifically to enable Windows support, so I think that it should be part of this change. Using the FileHandle
was the way around the FSR conversions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I will update the code to support Windows as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compnerd Thanks for the suggestions. I have updated the init method. Now it supports windows as well. Please do a round of review when you get a chance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a better solution would be to add an internal typealias for FSR
#if os(windows)
internal typealias _FileSystemRepresentation = UnsafePointer<UInt16>
#else
internal typealias _FileSystemRepresentation = UnsafePointer<Int8>
#endif
And use that in the signatures for these internal functions. I guess FileManager.fileSystemRepresentation(withPath path: String) -> UnsafePointer<Int8>
is technically broken on Windows anyway but can probably be ignored for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we don't want to break the public interfaces, I think that we should convert across the encodings.
Foundation/FileManager.swift
Outdated
defer { | ||
buffer1.deallocate() | ||
buffer2.deallocate() | ||
} | ||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bleeding whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The space between defer
and the next likes seems necessary, but If you feel strongly about this I will update it.
Also while we are in the topic, I have noticed a couple more unnecessary whitespaces as well in the same method; I will remove them too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having an empty line is not an issue, its the trailing whitespace which is the problem (the large green rectangle).
Foundation/FileHandle.swift
Outdated
guard fd > 0 else { return nil } | ||
|
||
#if os(Windows) | ||
self.init(handle: HANDLE(bitPattern: _get_osfhandle(fd))!, closeOnDealloc: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you use the init(fileDescriptor:closeOnDealloc:)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not notice that init
method; I will update the code. Thank you.
…a() in order to avoid calling fstat, alloc and dealloc while reading a file * New internal init method introduced to init with fileSystemRepresentation UnsafeMutablePointer<Int8> * New internal method _readBytes() introduced for continuous iteration of reading a file without allocating and deallocating buffer memory.
…leSystemRepresentation:flags:createMode:).
adf41ce
to
3e6884b
Compare
…nto:lenght) in FileHandle
3e6884b
to
5e020b8
Compare
@swift-ci please test |
@compnerd Looks like the compilation failed. I have built and ran the test cases using Xcode-Beta 10.2 beta 4 (10P107d) using Swift Development Snapshot 2019-03-17 (a) snapshot, successfully. Not sure if it is CI setup issue. |
@swift-ci please test |
@karthikkeyan Don't worry too much about my |
FileHandler
APIs used to replace the curret implementation of the private method_compareFiles(withFileSystemRepresentation:andFileSystemRepresentation:size:bufSize:)
Bug Link: https://bugs.swift.org/browse/SR-9979