MCPcopy Create free account
hub / github.com/dnote/dnote / restoreBackup

Function restoreBackup

pkg/cli/migrate/legacy.go:186–209  ·  view source on GitHub ↗
(ctx context.DnoteCtx)

Source from the content-addressed store, hash-verified

184}
185
186func restoreBackup(ctx context.DnoteCtx) error {
187 var err error
188
189 defer func() {
190 if err != nil {
191 log.Printf(`Failed to restore backup for a failed migration.
192 Don't worry. Your data is still intact in the backup directory.
193 Get help on https://github.com/dnote/dnote/pkg/cli/issues`)
194 }
195 }()
196
197 srcPath := fmt.Sprintf("%s/.dnote", ctx.Paths.Home)
198 backupPath := fmt.Sprintf("%s/%s", ctx.Paths.Home, backupDirName)
199
200 if err = os.RemoveAll(srcPath); err != nil {
201 return errors.Wrapf(err, "Failed to clear current dnote data at %s", backupPath)
202 }
203
204 if err = os.Rename(backupPath, srcPath); err != nil {
205 return errors.Wrap(err, `Failed to copy backup data to the original directory.`)
206 }
207
208 return nil
209}
210
211func clearBackup(ctx context.DnoteCtx) error {
212 backupPath := fmt.Sprintf("%s/%s", ctx.Paths.Home, backupDirName)

Callers 1

performMigrationFunction · 0.85

Calls 1

PrintfFunction · 0.92

Tested by

no test coverage detected