WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@AZero13
Copy link
Contributor

@AZero13 AZero13 commented Dec 5, 2025

The if statement appears inverted: setxattr follows simlinks: lsetxattr does not.

Additionally, _extendedAttributes was ignoring simlinks entirely.

Both of these issues have been addressed.

@AZero13
Copy link
Contributor Author

AZero13 commented Dec 8, 2025

@jmschonfeld ping?

@AZero13
Copy link
Contributor Author

AZero13 commented Dec 9, 2025

@jmschonfeld @compnerd ping?

@jmschonfeld
Copy link
Contributor

@jmschonfeld @compnerd ping?

It's on my list to circle back and review when I have a moment - no need to ping 🙂. Will be working my way through the handful of PRs open to review

@jmschonfeld
Copy link
Contributor

@swift-ci please test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

The code change looks fine, needs fixes for the tests.

@AZero13
Copy link
Contributor Author

AZero13 commented Dec 9, 2025

I fixed it, but also noticed we weren't passing followSymlinks to _extendedAttributes when the test failed on Darwin so. @compnerd

@AZero13 AZero13 force-pushed the mistake branch 3 times, most recently from 406328d to e1179f0 Compare December 9, 2025 21:36
@AZero13 AZero13 requested a review from jmschonfeld December 10, 2025 14:11
@AZero13 AZero13 force-pushed the mistake branch 2 times, most recently from 5505996 to 0c68c6a Compare December 10, 2025 15:36
@AZero13 AZero13 force-pushed the mistake branch 2 times, most recently from bd02eaa to b179951 Compare December 10, 2025 17:44
@AZero13 AZero13 requested a review from jmschonfeld December 10, 2025 17:44
@AZero13 AZero13 force-pushed the mistake branch 3 times, most recently from 8956f2e to 979d225 Compare December 10, 2025 21:57
@AZero13 AZero13 requested a review from jmschonfeld December 10, 2025 21:58
@jmschonfeld
Copy link
Contributor

@swift-ci please test

@AZero13 AZero13 changed the title FileManager: lsetxattr and setxattr are swapped Fix FileManager extended attribute symlink handling Dec 10, 2025
@AZero13 AZero13 force-pushed the mistake branch 3 times, most recently from 5267a46 to 0dd4d06 Compare December 10, 2025 22:29
@AZero13 AZero13 changed the title Fix FileManager extended attribute symlink handling Fix FileManager's extended attribute symlink handling Dec 10, 2025
@AZero13 AZero13 force-pushed the mistake branch 2 times, most recently from 037f442 to 9e17700 Compare December 10, 2025 22:35
@AZero13
Copy link
Contributor Author

AZero13 commented Dec 11, 2025

@jmschonfeld Can we please test and merge?

var extendedAttrs: [String : Data] = [:]
var current = keyList.baseAddress!
let end = keyList.baseAddress!.advanced(by: keyList.count)
let end = keyList.baseAddress!.advanced(by: size)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this was changed in a recent commit (hard to determine with force pushes rather than follow-on commits which are easier to review). Is there a reason you're switching to use the passed in size here rather than using the size of the allocation returned by the allocate function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes — the size variable gets updated by the second listxattr/extattr_list_* call to reflect the actual number of bytes written.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case if size is potentially different (if the file system changes and the number of attributes are removed) can we add an assertion that size <= keyList.count? In most cases I assume this shouldn't be an issue, but I'm wary that trusting this value could in some edge case inadvertently introduce a buffer overread here if size somehow becomes something larger than our allocation after it is overwritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If anything I'd say the opposite is more likely to happen: if keyList.count changes between allocation and read then this can happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think I'm fully following - in what situation would keyList.count change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is best for another PR. I'll revert it.

if error.code == .featureUnsupported { return }
guard let posix = error.underlying as? POSIXError else { throw error }
#if canImport(Darwin)
guard posix.code == .ENOTSUP || posix.code == .EOPNOTSUPP else { throw error }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason why ENOTSUP is guarded for Darwin only here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because ENOTSUP is not an error code on Linux.

I tried and it didn't compile.

Copy link
Contributor

Choose a reason for hiding this comment

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

ENOTSUP is an error code on Linux as far as I can tell if I'm reading the man pages correctly, but it looks like it has the same value as EOPNOTSUPP so there's no distinction. It looks like we also don't have a POSIXErrorCode.EOPNOTSUP for it which is likely the compilation error you were seeing (either intentionally because it's not necessary or just because nobody has ended up needing it). If that's the case, can you leave a comment about why this distinction is here so it's clear that ENOTSUP is not distinct from EOPNOTSUPP on non-Darwin platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@AZero13 AZero13 requested a review from jmschonfeld December 11, 2025 19:10
@AZero13
Copy link
Contributor Author

AZero13 commented Dec 11, 2025

I think this is as heavy as change now as it should get. We should merge this

I'll save the count and size replacement for another PR. That has been reverted back @jmschonfeld

@jmschonfeld
Copy link
Contributor

@swift-ci test

@AZero13
Copy link
Contributor Author

AZero13 commented Dec 12, 2025

Test failed because of a permission error on linux. @jmschonfeld what to do? How am I supposed to fix that in the test

@AZero13 AZero13 force-pushed the mistake branch 4 times, most recently from fd46df6 to 3adb585 Compare December 12, 2025 18:26
@AZero13
Copy link
Contributor Author

AZero13 commented Dec 12, 2025

Ugh I had to fix the tests to use rawvalue. The previous version passed locally, but not on the CI. My bad...

The if statement appears inverted:  setxattr follows simlinks: lsetxattr does not.

Additionally, _extendedAttributes was ignoring simlinks entirely.

Both of these issues have been addressed.
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.

3 participants