Repository navigation
Conversation
CopySection adds a copy of a section with its keys, values and comments under a new name, and RenameSection renames a section in place. Section.Name now takes the read lock, since a rename changes it (#280).
3 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
Adds two
Filemethods next toNewSectionandDeleteSection, for editing files such asmy.cnfwhere a new instance starts from an existing one:CopySection(name, newName)adds an independent copy after the last section: its comment, keys, values, shadow and nested values, key comments, or its raw body. The trailing comments of the file aren't copied.RenameSection(name, newName)renames the section where it is.*Sectionand*Keyvalues held for it see the new name.[mysqld.extra]are neither copied nor renamed; callers can loop overChildSections().GetSection, and keep sections of a name indexed in file order. The default section can't be renamed.newNamelower-cased, asNewSectiondoes, now through a shared helper.Clonewas considered as a name, but in Go it usually means a detached copy (maps.Clone,bytes.Clone), and this one gets a name inside the file.Section.Name()now takes the read lock, since a rename changes it. Nothing in the package calls it.Link to the issue: closes #280
Checklist
AI usage
Written by Amp (an AI coding agent) at the maintainer's request. Validation:
go test ./...,go vet, 20 s ofFuzzWriteRoundTrip, and a scratch-racerun ofNameandSectionNamesagainst concurrent renames and copies.TestFile_CopyRenameSectionchecks the written copy, that it's independent of the original, held values after a rename, every error case, case-insensitive names and non-unique section order.