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

Change the directory certificates are stored in #28

Merged
merged 6 commits into from
Apr 12, 2024
Merged

Change the directory certificates are stored in #28

merged 6 commits into from
Apr 12, 2024

Conversation

nogweii
Copy link
Contributor

@nogweii nogweii commented Apr 12, 2024

The new directory is compliant with the XDG Basedir specification.

The library will migrate the old directory to the new directory when it is not destructive.

Closes #27 .

Types of Changes

  • New feature.
  • Breaking change.

Contribution

@nogweii
Copy link
Contributor Author

nogweii commented Apr 12, 2024

@ioquatix I have configured my editor to automatically strip trailing whitespace, so I've gone and applied that to every ruby file in the project (and updating editorconfig to match). If you don't want that, I can easily revert the change.

And if you didn't know, github has a feature to hide whitespace changes in the diff view. Makes it easier to see the actual changes outside of the formatting change. 😄

@ioquatix
Copy link
Member

I don't normally strip trailing whitespace, and would prefer if that change wasn't included in this PR thanks :)

Copy link
Member

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

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

Looking great, just a few minor comments!

lib/localhost/authority.rb Outdated Show resolved Hide resolved
lib/localhost/authority.rb Outdated Show resolved Hide resolved
lib/localhost/authority.rb Outdated Show resolved Hide resolved
The new directory is compliant with the XDG Basedir specification[1].
The library will migrate the old directory to the new directory when
it is not destructive.

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
@nogweii
Copy link
Contributor Author

nogweii commented Apr 12, 2024

Rebased to remove the misc whitespace and CI iteration commits. 😄

Copy link
Member

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

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

Great, excellent work.

config/sus.rb Outdated Show resolved Hide resolved
ioquatix and others added 2 commits April 12, 2024 15:00
Make sure to require FileUtils

Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
config/sus.rb Outdated Show resolved Hide resolved
@@ -196,6 +197,7 @@ def load(path = @root)
end

def save(path = @root)
migrate_legacy_authority_path(path)
Dir.mkdir(path, 0700) unless File.directory?(path)
Copy link
Member

Choose a reason for hiding this comment

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

This line fails on external tests, where the XDG state directory doesn't exist.

I wonder if we should use FileUtils.mkdir_p here instead?

Should we be creating .local if it doesn't exist?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

The question is, for users who don't use .local, is it appropriate for random applications to create it? Does XDG have guidelines we can follow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was thinking about that. It seems like we should. The basedir spec doesn't seem to have a strong opinion.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, what I'd suggest we do, is move that into a separate operation, at least initially.

Copy link
Member

Choose a reason for hiding this comment

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

I think initially, let's detect if we need to do it in Authority.path.

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, when attempting to write a file, the destination directory is non-existent an attempt should be made to create it with permission 0700. If the destination directory exists already the permissions should not be changed. The application should be prepared to handle the case where the file could not be written, either because the directory was non-existent and could not be created, or for any other reason. In such case it may choose to present an error message to the user.

is what the spec says, immediately after discussing the config directory, but I think it applies to stateful files like this as well.

For non-Linux systems, like MacOS, XDG doesn't make sense and yet it also makes sense. (It seems like CLI tools will use XDG anyways, but graphical ones will use ~/Library/)

@nogweii
Copy link
Contributor Author

nogweii commented Apr 12, 2024

@ioquatix since we're considering doing I/O actions in Authority.path, should the migration be merged into that method as well?

I had split it out into a separate method in order to avoid any side-effects from instantiation, but that would no longer be true with the call to FileUtils.

@ioquatix
Copy link
Member

I had split it out into a separate method in order to avoid any side-effects from instantiation, but that would no longer be true with the call to FileUtils.

Yes, I think that's a good idea.

@nogweii
Copy link
Contributor Author

nogweii commented Apr 12, 2024

I think the three failing checks aren't related, so this is finally ready for merging if you want. 😸

@ioquatix ioquatix merged commit ecde804 into socketry:main Apr 12, 2024
19 of 22 checks passed
@ioquatix
Copy link
Member

Thanks, this looks great, I'll test it locally and cut a release.

@ioquatix ioquatix added this to the v1.3.0 milestone Apr 12, 2024
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.

Support XDG spec, or at least an environment variable to customize ~/.localhost path
2 participants