-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
xar: fix Linux build on staging-next #352507
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
pkgs/by-name/xa/xar/patches/0020-Fall-back-to-readlink-on-Linux.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Randy Eckenrode <randy@largeandhighquality.com> | ||
Date: Wed, 30 Oct 2024 20:19:20 -0400 | ||
Subject: [PATCH 20/20] Fall back to readlink on Linux | ||
|
||
--- | ||
xar/lib/archive.c | 21 +++++++++++++++++++++ | ||
1 file changed, 21 insertions(+) | ||
|
||
diff --git a/xar/lib/archive.c b/xar/lib/archive.c | ||
index b7f9cbf..3a79c74 100644 | ||
--- a/xar/lib/archive.c | ||
+++ b/xar/lib/archive.c | ||
@@ -507,10 +507,31 @@ xar_t xar_fdopen_digest_verify(int fd, int32_t flags, void *expected_toc_digest, | ||
// If there are hardlinks, the path we pick is the most recently opened by | ||
// the filesystem; which is effectively random. | ||
char path_buff[PATH_MAX]; | ||
+#if defined(__APPLE__) | ||
if (fcntl(fd, F_GETPATH, path_buff) < 0) { | ||
close(fd); | ||
return NULL; | ||
} | ||
+#elif defined(__linux__) | ||
+ // Linux has to get the path to the file via `/proc`. | ||
+ char proc_buff[PATH_MAX]; | ||
+ if (snprintf(proc_buff, PATH_MAX, "/proc/self/fd/%i", fd) < 0) { | ||
+ close(fd); | ||
+ return NULL; | ||
+ } | ||
+ if (readlink(proc_buff, &path_buff, PATH_MAX) < 0) { | ||
+ close(fd); | ||
+ return NULL; | ||
+ } | ||
+ // The filename is the file’s when the fd was created. Check to make sure it still exists. | ||
+ struct stat stat_buff; | ||
+ if (stat(path_buff, &stat_buff) < 0) { | ||
+ close(fd); | ||
+ return NULL; | ||
+ } | ||
+#else | ||
+#error "Unknown platform. Please update with an implementation of `F_GETPATH`." | ||
+#endif | ||
|
||
// Don't trust the position of the descriptor we were given, reset it back to 0 | ||
if (lseek(fd, 0, SEEK_SET) != 0) { | ||
-- | ||
2.47.0 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really have to check that the file exists? How does F_GETPATH on Darwin handle this case (e.g. fcntl after unlink)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. The documentation just says it gets the path. I’m going to write some test programs later today to probe the behavior to see what Darwin does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darwin tracks name changes for renames. When the file is unlinked,
F_GETPATH
appears to return the last name it had. It may be possible to track renames in Linux (not sure), but it’s probably not worth the effort. Bailing if the underlying file was removed or renamed seems like the safest/easiest option.