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

isDeletableFile Implementation + Tests #1670

Merged
merged 3 commits into from Sep 14, 2018
Merged

Conversation

rauhul
Copy link
Contributor

@rauhul rauhul commented Aug 27, 2018

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.

func test_isDeletableFile() {
// TODO: Implement test
// how to test?
}
Copy link
Collaborator

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

Copy link
Contributor Author

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?

Copy link
Collaborator

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

@spevans
Copy link
Collaborator

spevans commented Sep 1, 2018

@swift-ci test

@spevans
Copy link
Collaborator

spevans commented Sep 1, 2018

@swift-ci test

1 similar comment
@spevans
Copy link
Collaborator

spevans commented Sep 2, 2018

@swift-ci test

@rauhul
Copy link
Contributor Author

rauhul commented Sep 7, 2018

@parkera @spevans can this be merged?

@alblue
Copy link
Contributor

alblue commented Sep 7, 2018

Seems reasonable to me. WDYT @millenomi @phausler ?

Copy link
Member

@phausler phausler left a 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.

@parkera
Copy link
Member

parkera commented Sep 13, 2018

@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
Copy link
Contributor

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.

@millenomi
Copy link
Contributor

@swift-ci please test and merge

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.

None yet

7 participants