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

Set a default locale when building images #151

Merged
merged 4 commits into from
Oct 10, 2023
Merged

Set a default locale when building images #151

merged 4 commits into from
Oct 10, 2023

Conversation

sil2100
Copy link
Collaborator

@sil2100 sil2100 commented Oct 10, 2023

Do it only in the case where no other customization set a default locale. This is to fix this bug:
https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/2038945

livecd-rootfs was always setting a default locale of C.UTF-8, so we want to do the same.

@sil2100 sil2100 requested a review from mwhudson October 10, 2023 20:07
Copy link
Contributor

@mwhudson mwhudson left a comment

Choose a reason for hiding this comment

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

Some quibbles that I think won't make any difference in practice. I think I'd be ok merging this under the circumstances but would want to follow up fairly promptly...

return nil
}

err = osMkdirAll(defaultPath, 0755)
Copy link
Contributor

Choose a reason for hiding this comment

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

etc/default is shipped by base-files so i don't think this is necessary but it's also not harmful i guess.

defaultPath := filepath.Join(classicStateMachine.tempDirs.chroot, "etc", "default")
localePath := filepath.Join(defaultPath, "locale")
localeBytes, err := osReadFile(localePath)
if err == nil && strings.Contains(string(localeBytes), "LANG=") {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a pain but this should really check for the regex "^LANG=" right? This would match "#LANG=" ...

return fmt.Errorf("Error creating default directory: %s", err.Error())
}

err = osWriteFile(localePath, []byte("# Default Ubuntu locale\nLANG=C.UTF-8\n"), 0644)
Copy link
Contributor

Choose a reason for hiding this comment

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

This overwrites any previous file right? In practice this is extremely likely to be fine but there are ways it could incorrect I suppose, like if the image creator wants to set LC_MESSAGES to a different value to LC_COLLATE for some insane reason.

@sil2100
Copy link
Collaborator Author

sil2100 commented Oct 10, 2023

Thank you for the review Michael! I made the match taking into consideration LANG and LC_*, and also made the match from the start of the line (+ tests). Let's see if all the tests pass, if yes, I'll merge it. We can always make it better later.

@sil2100
Copy link
Collaborator Author

sil2100 commented Oct 10, 2023

The tests are failing because of out-of-disk-space errors, but trunk is failing right now as well - so unrelated. A shame as this means there's no coverage, but I don't think I have the capacity to take care of it as part of this PR.

@sil2100 sil2100 merged commit e3b1b72 into main Oct 10, 2023
8 of 10 checks passed
@sil2100 sil2100 deleted the set-default-locale branch October 10, 2023 22:39
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