Skip to content

improve testing for readability/writability of shared directories #4079

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

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Feb 2, 2022

motivaiton: cleaner code

changes: user new FS APIs to test for readability/writability instead of attempting to create a temp file

@tomerd tomerd requested a review from yim-lee February 2, 2022 20:12
motivaiton: cleaner code

changes: user new FS APIs to test for readability/writability instead of attempting to create a temp file
@tomerd tomerd force-pushed the refactor/user-readability-writability-apis branch from 53a4d7d to cea3856 Compare February 2, 2022 20:13
@tomerd
Copy link
Contributor Author

tomerd commented Feb 2, 2022

@yim-lee wdyt?

@tomerd
Copy link
Contributor Author

tomerd commented Feb 2, 2022

@swift-ci please smoke test

@tomerd tomerd changed the title improve testing fo readability/writability of share d directories improve testing fo readability/writability of shared directories Feb 2, 2022
try withTemporaryFile(dir: path.parentDirectory) { _ in }
} catch {
self.observabilityScope.emit(warning: "\(path.parentDirectory) is not accessible or not writable, not using .netrc file in it: \(error)")
guard localFileSystem.exists(path) && localFileSystem.isReadable(path) else {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need isWritable because NetrcAuthorizationProvider supports edits (addOrUpdate), or we remove that capability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addOrUpdate is outside the AuthorizationProvider protocol iirc, so theoretically you would need to cast into NetrcAuthorizationProvider to use it?

Copy link
Contributor

@yim-lee yim-lee Feb 2, 2022

Choose a reason for hiding this comment

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

Yes, addOrUpdate is not part of the AuthorizationProvider protocol currently, but I see potential of it being added later (e.g., for registry authn). With this in mind, we should make this isWritable because we are bound forget to change it later.

Copy link
Contributor Author

@tomerd tomerd Feb 3, 2022

Choose a reason for hiding this comment

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

@yim-lee hesitant about requiring write access to this one specifically since often its a readonly file

we should def consider that if we are to offer a "write" netrc utility. atm i dont think we do, we can also comment out that code with a comment to make it more clear?

Copy link
Contributor

@yim-lee yim-lee Feb 3, 2022

Choose a reason for hiding this comment

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

we should def consider that if we are to offer a "write" netrc utility

We would have to, for saving registry credentials.

Copy link
Contributor

@yim-lee yim-lee Feb 3, 2022

Choose a reason for hiding this comment

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

One option might be to modify NetrcAuthorizationProvider.addOrUpdate so it does the isWritable check each time, and then we keep this isReadable.

Or, since write would fail anyway, keep NetrcAuthorizationProvider.addOrUpdate as-is and let it throw the file system error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yim-lee happy to add such check if you think its useful. lmk!

Copy link
Contributor

@yim-lee yim-lee left a comment

Choose a reason for hiding this comment

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

Leaving the check for .netrc isReadable instead of isWritable would mean that if user performs any action that would trigger a write on .netrc, the operation would fail. I guess this UX isn't too bad.

@tomerd tomerd changed the title improve testing fo readability/writability of shared directories improve testing for readability/writability of shared directories Feb 3, 2022
@tomerd tomerd merged commit 5a259c6 into swiftlang:main Feb 3, 2022
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.

2 participants