Skip to content

Commit

Permalink
fix: Fix "invalid cross-device link" error
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Oct 6, 2023
1 parent 8779761 commit 8ffb868
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,28 @@ func openAndTemplate(cmd *cobra.Command, conf config.Config, p string) (err erro
}

if err := os.Rename(temp.Name(), p); err != nil {
return fmt.Errorf("%s: %w", p, err)
log.Debug("failed to rename file, attempting to copy contents")

in, err := os.Open(temp.Name())
if err != nil {
return fmt.Errorf("%s: %w", p, err)
}
defer func() {
_ = in.Close()
}()

out, err := os.OpenFile(p, os.O_WRONLY|os.O_TRUNC, stat.Mode())
if err != nil {
return fmt.Errorf("%s: %w", p, err)
}

if _, err := io.Copy(out, in); err != nil {
return fmt.Errorf("%s: %w", p, err)
}

if err := out.Close(); err != nil {
return err
}
}
} else {
if _, err := fmt.Fprint(cmd.OutOrStdout(), s); err != nil {
Expand Down

0 comments on commit 8ffb868

Please sign in to comment.