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
isDeletableFile Implementation + Tests #1670
Conversation
TestFoundation/TestFileManager.swift
Outdated
func test_isDeletableFile() { | ||
// TODO: Implement test | ||
// how to test? | ||
} |
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.
You could create a file and check its is deletable. Also check a file that should fail eg /dev/null
and also check /
to validate the parent checking code
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.
Just to confirm, we would expect the created file to be deletable, correct?
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.
Yes, thats correct. You should be able to create a file that fails by putting it into a subdirectory with no permissions:
eg
mkdir dir1
touch dir1/file1
chmod 000 dir1
isDeletableFile("dir1/file1") -> false
chmod 755 dir1
isDeletableFile("dir1/file1") -> true
@swift-ci test |
a3e8851
to
bd0690a
Compare
@swift-ci test |
1 similar comment
@swift-ci test |
Seems reasonable to me. WDYT @millenomi @phausler ? |
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.
looks good to me, this is pretty much on par with what we do for Darwin.
@millenomi you want to do the final approval here? |
open func isDeletableFile(atPath path: String) -> Bool { | ||
NSUnimplemented() | ||
// Get the parent directory of supplied path | ||
let parent = path._nsObject.deletingLastPathComponent |
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.
This is pretty close to the Darwin implementation! That implementation also special-cases the empty string to mean the current directory, but it's not behavior that's documented, so I don't think we need to port it.
@swift-ci please test and merge |
Tried to best match the suggested implementation from the Swift Forum.
I wasn't exactly sure how to write tests for these methods. My tests attempt to check that the result of
isReadableFile
,isWritableFile
,isExecutableFile
match the value one would receive by directly checking the file's permission bits.