Skip to content

Add an option to not delete TemporaryFile on dealloc #1625

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 2 commits into from
Jun 27, 2018
Merged

Add an option to not delete TemporaryFile on dealloc #1625

merged 2 commits into from
Jun 27, 2018

Conversation

czechboy0
Copy link
Member

It's sometimes useful to create a temp file but keep it around for a little bit longer, instead of automatically deleting it on dealloc. TemporaryDirectory already has a similar option.

@czechboy0
Copy link
Member Author

@aciidb0mb3r

file.fileHandle.seek(toFileOffset: 0)
// Read the contents.
let contents = try? file.fileHandle.readFileContents()
XCTAssertEqual(contents, "foobarbaz")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test could be simplified I think. We can write data in the do block and then just read it outside the block using the FileSystem .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I kept consistent with the other tests in this file, do you think they should all be changed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a reason to do that for other tests but anyway it was just a nitpick. LGTM!

filePath = file.path
}
// File should not be deleted.
XCTAssertTrue(isFile(filePath))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also remove the temporary file before exiting this test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed.

@aciidgh
Copy link
Contributor

aciidgh commented Jun 27, 2018

@swift-ci please smoke test

@czechboy0
Copy link
Member Author

CI green \o/

@aciidgh aciidgh merged commit 6de5b27 into swiftlang:master Jun 27, 2018
@czechboy0 czechboy0 deleted the noDeleteTempFile branch June 29, 2018 15:21
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.

2 participants