Skip to content

Commit

Permalink
Address metadata file checking review concern
Browse files Browse the repository at this point in the history
The logic for checking metadata files in the Migration method exists in
Exercise's HasMetadata(). I previously avoided using these methods
because this adds duplicate calls to MetadataFilepath() but this might
be worth trading for DRYing up the file checking logic.
  • Loading branch information
jdsutherland committed Aug 29, 2018
1 parent f244b57 commit a79167b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions workspace/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,17 @@ func (e Exercise) HasLegacyMetadata() (bool, error) {
// This is a noop if the metadata file isn't legacy.
// If both legacy and modern metadata files exist, the legacy file will be deleted.
func (e Exercise) MigrateLegacyMetadataFile() error {
legacyMetadataFilepath := e.LegacyMetadataFilepath()
metadataFilepath := e.MetadataFilepath()

if _, err := os.Lstat(legacyMetadataFilepath); err != nil {
if ok, _ := e.HasLegacyMetadata(); !ok {
return nil
}
dir := filepath.Join(filepath.Dir(legacyMetadataFilepath), ignoreSubdir)
if err := os.MkdirAll(dir, os.FileMode(0755)); err != nil {
legacyMetadataFilepath := e.LegacyMetadataFilepath()
if err := os.MkdirAll(
filepath.Join(filepath.Dir(legacyMetadataFilepath), ignoreSubdir),
os.FileMode(0755)); err != nil {
return err
}
if _, err := os.Lstat(metadataFilepath); err != nil {
if err := os.Rename(legacyMetadataFilepath, metadataFilepath); err != nil {
if ok, _ := e.HasMetadata(); !ok {
if err := os.Rename(legacyMetadataFilepath, e.MetadataFilepath()); err != nil {
return err
}
} else {
Expand Down

0 comments on commit a79167b

Please sign in to comment.