-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement contentsOfDirectoryAtPath #134
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 contentsOfDirectoryAtPath #134
Conversation
Overall this looks pretty good, with the minor comment on Can you rebase this on top of master and into a single commit? |
Not a problem, I'll do so tonight once I've tested the |
@parkera Rebased and squashed, hopefully that's all fixed! Your comments about the |
|
||
defer { | ||
closedir(dir) | ||
dir.destroy() |
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 am not certain this is the correct usage here; destroy is usually reserved from the initialized from swift scope buffers.
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.
@phausler That may be true, but I wasn't sure. It doesn't cause any errors, but if it's not needed then I can remove it.
On 17 Dec 2015, at 17:30, Philippe Hausler [email protected] wrote:
In Foundation/NSFileManager.swift:
public func subpathsOfDirectoryAtPath(path: String) throws -> [String] {
NSUnimplemented()
var contents : [String] = [String]()
let dir = opendir(path)
if dir == nil {
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.FileReadNoSuchFileError.rawValue, userInfo: [NSFilePathErrorKey: path])
}
defer {
closedir(dir)
I am not certain this is the correct usage here; destroy is usually reserved from the initialized from swift scope buffers.dir.destroy()
—
Reply to this email directly or view it on GitHub.
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.
After looking into it - it seems to be almost a no-op in this case
TIL...
Interesting - did some digging around in the standard lib:
It claims
/// Destroy the object the pointer points to.
///
/// - Precondition: The memory is initialized.
///
/// - Postcondition: The value has been destroyed and the memory must
/// be initialized before being used again.
and then promptly calls
Builtin.destroy(Memory.self, _rawValue)
Which in turn ends up dealing with witness tables and seems to be primarily for object based buffers. So it would probably only matter if this was happening on UnsafeMutablePointer of CF types which are translated to swift retain/released objects.
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.
Interesting. Sounds like I can just remove it then without any downsides. I'll update this PR now.
Fixed the concerns regarding |
looks pretty reasonable overall to me; just need to run tests before merging |
let int32Ptr = unsafeBitCast(ptr, UnsafePointer<UInt8>.self) | ||
return Int32(int32Ptr.memory) | ||
}) { | ||
if entryType == DT_DIR { |
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.
on ubuntu I get this error:
Foundation/NSFileManager.swift:280:38: error: binary operator '==' cannot be applied to operands of type 'Int32' and 'Int'
if entryType == DT_DIR {
~~~~~~~~~ ^ ~~~~~~
Foundation/NSFileManager.swift:280:38: note: overloads for '==' exist with these partially matching parameter lists: (Int32, Int32), (Int, Int)
if entryType == DT_DIR {
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.
Great. In OS X DT_DIR is an Int32
, but obviously it's an Int
on Linux. I'll add a conditional.
Implementing NSFileManager::contentsOfDirectoryAtPath and NSFileManager::subpathsOfDirectoryAtPath.
Fixed, hopefully. I haven't tested on Linux, I'm setting up a VM to do so now. |
yep, seems to be good now. |
…sOfDirectoryAtPath Implement contentsOfDirectoryAtPath
👍 |
[test] Add a test for SwiftPM integration
[pull] swiftwasm from main
Implementing NSFileManager::contentsOfDirectoryAtPath() and NSFileManager::subpathsOfDirectoryAtPath().
Error messages aren't currently an exact match for the standard Foundation library, which throws:
Whereas this commit throws:
However, I lack the knowledge to know what I'm missing with the
NSError
.Otherwise, the test cases pass and this should hopefully work.