(ctx context.DnoteCtx)
| 184 | } |
| 185 | |
| 186 | func 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 | |
| 211 | func clearBackup(ctx context.DnoteCtx) error { |
| 212 | backupPath := fmt.Sprintf("%s/%s", ctx.Paths.Home, backupDirName) |
no test coverage detected