Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close dest before source renaming #39

Merged
merged 1 commit into from Jun 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions rewrite/rewrite.go
Expand Up @@ -168,24 +168,34 @@ func rewriteImportsInFile(fi string, rw func(string) string, rwLock *sync.Mutex)
return err
}

// Write the imports
_, err = buf.WriteTo(tmp)
if err != nil {
return err
}

// Copy the rest
src, err := os.Open(fi)
if err != nil {
return err
}
defer src.Close()

_, err = src.Seek(int64(oldImportsEnd), io.SeekStart)
if err != nil {
src.Close()
return err
}

buf.WriteTo(tmp)

_, err = io.Copy(tmp, src)
if err != nil {
src.Close()
return err
}

// Ignore any errors, we didn't modify this file.
src.Close()

// Update the file
if err = tmp.Close(); err != nil {
return err
}
Expand Down