You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/10/23 17:31:20 UTC
[mynewt-newt] 02/02: Use `util.MoveDir()` instead of `os.Rename()`
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git
commit bc09bb3b75e7d656869707846497e55f1b78de83
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Wed Oct 23 09:32:46 2019 -0700
Use `util.MoveDir()` instead of `os.Rename()`
`os.Rename()` fails if the source and destination paths reside on
different disks. The `util.MoveDir()` function handles both cases (same
disk and different disks).
Before this commit, a cross-disk rename might cause the newt command to
fail with an error like this:
Error: rename /tmp/mynewt-user-pre-link391870512/src /home/me/repo/bin/targets/my_blinky_sim/user/pre_link/src: invalid cross-device link
---
newt/builder/extcmd.go | 4 ++--
newt/project/pkgwriter.go | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/newt/builder/extcmd.go b/newt/builder/extcmd.go
index cddea76..0d106fb 100644
--- a/newt/builder/extcmd.go
+++ b/newt/builder/extcmd.go
@@ -28,8 +28,8 @@ func replaceArtifactsIfChanged(oldDir string, newDir string) error {
log.Debugf("changes detected; replacing %s with %s", oldDir, newDir)
os.RemoveAll(oldDir)
- if err := os.Rename(newDir, oldDir); err != nil {
- return util.ChildNewtError(err)
+ if err := util.MoveDir(newDir, oldDir); err != nil {
+ return err
}
return nil
diff --git a/newt/project/pkgwriter.go b/newt/project/pkgwriter.go
index 5a0f6db..0501599 100644
--- a/newt/project/pkgwriter.go
+++ b/newt/project/pkgwriter.go
@@ -201,8 +201,8 @@ func (pw *PackageWriter) fixupPkg() error {
if err := os.MkdirAll(filepath.Dir(d2), os.ModePerm); err != nil {
return util.ChildNewtError(err)
}
- if err := os.Rename(d1, d2); err != nil {
- return util.ChildNewtError(err)
+ if err := util.MoveDir(d1, d2); err != nil {
+ return err
}
}
}
@@ -224,8 +224,8 @@ func (pw *PackageWriter) fixupPkg() error {
for _, f1 := range files {
f2 := replaceText(f1, table)
if f2 != f1 {
- if err := os.Rename(f1, f2); err != nil {
- return util.ChildNewtError(err)
+ if err := util.MoveDir(f1, f2); err != nil {
+ return err
}
}
}