Skip to content

[wasm] Do not set permissions in Data.write #4976

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

Merged
merged 1 commit into from
Jun 9, 2024

Conversation

kkebo
Copy link
Contributor

@kkebo kkebo commented Jun 8, 2024

This fixes swiftwasm/swift#5584.

This PR does not affect platforms other than WASI.

@kateinoigakukun
Copy link
Member

Good catch! Don't we need to fix _setAttributes too?

@kkebo
Copy link
Contributor Author

kkebo commented Jun 9, 2024

@kateinoigakukun

Don't we need to fix _setAttributes too?

I'm sorry, but I don't understand what you mean by "fix _setAttributes".

I changed permissions so that the condition of the if statement are always not satisfied instead of enclosing the following lines with #if !os(WASI).

(If you have a better solution, I'm ok to close this PR.)

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Jun 9, 2024

@kkebo Sorry, I meant it might be better to ignore the permission attribute within FileManager.setAttributes. Currently all users of the API also need to exclude FileAttributeKey.posixPermissions entry from the passing attributes manually as we do in this PR but it's just annoying for most of the use cases...

@kkebo
Copy link
Contributor Author

kkebo commented Jun 9, 2024

@kateinoigakukun Thank you. That makes sense and it can solve many problems with less code. On the other hand, since it is true that the posixPermissions key is not supported on WASI, I feel that we should throw an error and notify programmers, and also programmers should not try to set posixPermissions in the first place.

@kateinoigakukun
Copy link
Member

Okay, given that the API is not so widely used directly, asking users to change their code might be practically reasonable 👍

@kateinoigakukun
Copy link
Member

@swift-ci test

@kateinoigakukun kateinoigakukun merged commit ca3669e into swiftlang:main Jun 9, 2024
2 of 3 checks passed
@kkebo kkebo deleted the fix-nsdata-write-for-wasi branch June 9, 2024 10:29
@parkera
Copy link
Contributor

parkera commented Jun 10, 2024

We're going to lose this diff once we delete this file in the package branch. Please open a corresponding patch for https://github.com/apple/swift-foundation.

@parkera
Copy link
Contributor

parkera commented Jun 10, 2024

Actually, this one may persist because this change was only made to the class type NSData and not the struct - was that intentional?

@kkebo
Copy link
Contributor Author

kkebo commented Jun 11, 2024

@parkera

Actually, this one may persist because this change was only made to the class type NSData and not the struct - was that intentional?

At least in swift-corelibs-foundation, the Data.write method calls the NSData.write method and does not have its own implementation.

@parkera
Copy link
Contributor

parkera commented Jun 11, 2024

This will soon no longer be the case - see here: https://github.com/apple/swift-foundation/blob/main/Sources/FoundationEssentials/Data/Data%2BWriting.swift

@kkebo
Copy link
Contributor Author

kkebo commented Jun 11, 2024

Yes, I know swift-foundation's Data.write.

Besides, I have read your comment before, and I know we will eventually use the implementation of swift-foundation instead of this repository, but I don't know how much effort we need to make swift-foundation compatible with Wasm.

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.

Overwriting a file with Data.write(to:) causes an error
3 participants