Skip to content

Conversation

@JiaT75
Copy link
Contributor

@JiaT75 JiaT75 commented Oct 27, 2021

Moved the code changes out of the documentation changes to the man pages for archive_read_disk.

@mmatuska mmatuska merged commit f0726c1 into libarchive:master Nov 15, 2021
@emaste emaste mentioned this pull request Mar 30, 2024
15 tasks
"archive_read_disk_descend");

if (t->visit_type != TREE_REGULAR || !t->descend)
if (!archive_read_disk_can_descend(_a))

Choose a reason for hiding this comment

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

I think there is a problem in the archive_read_disk_can_descend() function. It calls archive_check_magic() which can return ARCHIVE_FATAL which becomes a return value of archive_read_disk_can_descend(). As it converted to bool that will cause the rest of the function to be skipped in case of bad magic. If the check above is removed as redundant in the future - this can lead to behavior change. Ideally, archive_read_disk_can_descend() should return ARCHIVE_OK or other statuses instead of bool and checked appropriately at callers. There are several call sites where there is no archive_check_magic() before invocation of archive_read_disk_can_descend().

Copy link
Contributor

Choose a reason for hiding this comment

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

archive_check_magic is a sanity check. If it triggers, the caller is doing something completely wrong.

Choose a reason for hiding this comment

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

The problem is bad interface - the archive_read_disk_can_descend() return BOOL and it is true when the sanity check fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Again, irrelevant. It's checked already just above this line.

@kientzle
Copy link
Contributor

kientzle commented Apr 3, 2024

archive_check_magic() is designed to be called at the beginning of each public API function. It helps guard against basic errors by software that uses libarchive. Changing archive_read_disk_can_descend() to use a different return type might be a reasonable change that would make the code easier to understand. But it is part of the public API (declared in archive.h) and so we can't change it without a major version bump. (Any PR that proposes changing this should be guarded with #if ARCHIVE_VERSION_NUMBER >= 4000000 to ensure it doesn't take effect before libarchive 4.0.)

For a trivial function like this, it might make sense to remove the magic check. Again, that check is there is to help developers use libarchive by giving them a clear error when they call functions that aren't reasonable in a certain context. For a trivial status function like this, that check is less useful.

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.

5 participants