MCPcopy
hub / github.com/etcd-io/bbolt / surgeryMetaUpdateFunc

Function surgeryMetaUpdateFunc

cmd/bbolt/command/command_surgery_meta.go:137–182  ·  view source on GitHub ↗
(srcDBPath string, cfg surgeryMetaUpdateOptions)

Source from the content-addressed store, hash-verified

135}
136
137func surgeryMetaUpdateFunc(srcDBPath string, cfg surgeryMetaUpdateOptions) error {
138 if _, err := checkSourceDBPath(srcDBPath); err != nil {
139 return err
140 }
141
142 if err := common.CopyFile(srcDBPath, cfg.outputDBFilePath); err != nil {
143 return fmt.Errorf("[meta update] copy file failed: %w", err)
144 }
145
146 // read the page size from the first meta page if we want to edit the second meta page.
147 var pageSize uint32
148 if cfg.metaPageId == 1 {
149 m0, _, err := ReadMetaPageAt(cfg.outputDBFilePath, 0, pageSize)
150 if err != nil {
151 return fmt.Errorf("read the first meta page failed: %w", err)
152 }
153 pageSize = m0.PageSize()
154 }
155
156 // update the specified meta page
157 m, buf, err := ReadMetaPageAt(cfg.outputDBFilePath, cfg.metaPageId, pageSize)
158 if err != nil {
159 return fmt.Errorf("read meta page %d failed: %w", cfg.metaPageId, err)
160 }
161 mChanged := updateMetaField(m, parseFields(cfg.fields))
162 if mChanged {
163 if err := writeMetaPageAt(cfg.outputDBFilePath, buf, cfg.metaPageId, pageSize); err != nil {
164 return fmt.Errorf("[meta update] write meta page %d failed: %w", cfg.metaPageId, err)
165 }
166 }
167
168 if cfg.metaPageId == 1 && pageSize != m.PageSize() {
169 fmt.Fprintf(os.Stdout, "WARNING: The page size (%d) in the first meta page doesn't match the second meta page (%d)\n", pageSize, m.PageSize())
170 }
171
172 // Display results
173 if !mChanged {
174 fmt.Fprintln(os.Stdout, "Nothing changed!")
175 }
176
177 if mChanged {
178 fmt.Fprintf(os.Stdout, "The meta page %d has been updated!\n", cfg.metaPageId)
179 }
180
181 return nil
182}
183
184func parseFields(fields []string) map[string]uint64 {
185 fieldsMap := make(map[string]uint64)

Callers 1

Calls 8

CopyFileFunction · 0.92
checkSourceDBPathFunction · 0.85
ReadMetaPageAtFunction · 0.85
updateMetaFieldFunction · 0.85
parseFieldsFunction · 0.85
writeMetaPageAtFunction · 0.85
PageSizeMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected