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

Fix _copyDirectoryMetadata compilation error on FreeBSD #1121

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

Conversation

michael-yuji
Copy link
Contributor

_copyDirectoryMetadata does not compile on FreeBSD since f{list,get}xattr is not available. Use extattr_*_fd to copy extended attributes recursively instead.

Unlike the Linux variant, extxattr_*(2) does not return an entry list with null terminating attribute names. Instead, each list entry consists of a single byte containing the length of the attribute name follow by the non-null terminating name itself.

To iterate each entry:

  • we prepare a null-terminating terminating temporary buffer of to store the entrylist, plus 1 null terminator.
  • we first get the length of the first entry
  • in each iteration, we store the length of next entry and replace the length byte of the next entry with NULL, this effectively make the current attribute name a NULL-terminating string, that we can feed to extattr_{get, set}_fd. Finally we set the current pointer to the next attribute name.

Apart from the difference in how the entry list is iterated, unlike Linux, the extended attributes namespaces are not determined by the prefix the attribute names. Instead, we need to iterator each namespace (EXTATTR_NAMESPACE_SYSTEM, EXTATTR_NAMESPACE_USER) separately.

@michael-yuji
Copy link
Contributor Author

@swift-ci please test

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.

1 participant