Skip to content

isDeletableFile Implementation + Tests #1670

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

Merged
merged 3 commits into from
Sep 14, 2018

Conversation

rauhul
Copy link
Member

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

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
Member 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
Contributor

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
Contributor

spevans commented Sep 1, 2018

@swift-ci test

@spevans
Copy link
Contributor

spevans commented Sep 1, 2018

@swift-ci test

1 similar comment
@spevans
Copy link
Contributor

spevans commented Sep 2, 2018

@swift-ci test

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

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

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

@swift-ci swift-ci merged commit ae4f64e into swiftlang:master Sep 14, 2018
@rauhul rauhul deleted the isDeletableFile branch September 20, 2018 04:58
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.

7 participants