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

Allow opening archive from IO instance #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sj26
Copy link
Contributor

@sj26 sj26 commented Aug 9, 2023

Description

Allow opening an archive from an #<IO> instance, like a #<File>. This is different to opening an FD because it will hold a reference to the IO in Ruby, within the Archive instance, ensuring the lifetime of the IO instance is tied to the lifetime of the Archive::Reader instance, as a nice way to ensure libarchive won't read from an FD that Ruby has since closed by GC'ing the IO instance.

Note there is no memory leak etc, the worst that currently happens is an error about reading from a closed FD. But this interface makes the FFI binding a nicer Ruby citizen.

Related Issue

Previously discussed in #75.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@sj26 sj26 requested review from a team as code owners August 9, 2023 05:10
@tpowell-progress
Copy link
Contributor

@sj26 Can you intentionally trigger the closed FD error? Wondering if it's something we can prevent from bubbling up.

@tpowell-progress tpowell-progress self-assigned this Aug 9, 2023
@tpowell-progress
Copy link
Contributor

@sj26 Also, you'll need to rebase from main to merge

This is discrete from fd because if we pass an fd into libarchive then
the caller is reponsible for making sure the opened of the fd survives
for the lifetime of the archive instance, but passing in an IO and
holding a reference in an instance variable ties the lifetime to the
archive instance and allows GC to work as per normal.

Signed-off-by: Samuel Cochran <[email protected]>
@sonarcloud
Copy link

sonarcloud bot commented Aug 11, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@tpowell-progress
Copy link
Contributor

@sj26 any thoughts on the FD error trapping? I'm assuming this bubbles up through the ffi from C?

@sj26
Copy link
Contributor Author

sj26 commented Aug 14, 2023

Sorry, that's getting out of my depth 😅

I've seen some errors, but I can't reliably replicate. Perhaps this isn't the issue I thought? I'm not sure. It's at the mercy of Ruby GC and object finalization.

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