Skip to content

Commit c8e2da4

Browse files
authored
test: add fallback to copy and delete for cross-device os.Rename fa… (#22556)
* testL add fallback to copy and delete for cross-device `os.Rename` failures when moving binary files. * refactor: use `mcnutils.CopyFile` for robust binary file copying. * docs: Add comment explaining os.Rename fallback to copy for cross-device links.
1 parent b288555 commit c8e2da4

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

test/integration/aaa_download_only_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"strings"
3535
"testing"
3636

37+
"k8s.io/minikube/pkg/libmachine/mcnutils"
3738
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
3839
"k8s.io/minikube/pkg/minikube/constants"
3940
"k8s.io/minikube/pkg/minikube/download"
@@ -296,8 +297,16 @@ func TestBinaryMirror(t *testing.T) {
296297
}
297298

298299
newBinaryPath := filepath.Join(newBinaryDir, binaryName)
300+
// Usage of os.Rename might result in "invalid cross-device link" error if the files are not on the same partition.
301+
// In that case, we fall back to copying the file.
299302
if err := os.Rename(binaryPath, newBinaryPath); err != nil {
300-
t.Errorf("Failed to move binary file: %+v", err)
303+
t.Logf("os.Rename failed, falling back to copy (likely cross-device): %v", err)
304+
if err := mcnutils.CopyFile(binaryPath, newBinaryPath); err != nil {
305+
t.Fatalf("Failed to copy binary file: %v", err)
306+
}
307+
if err := os.Remove(binaryPath); err != nil {
308+
t.Logf("Warning: Failed to remove original binary file: %v", err)
309+
}
301310
}
302311
if err := createSha256File(newBinaryPath); err != nil {
303312
t.Errorf("Failed to generate sha256 checksum file: %+v", err)

0 commit comments

Comments
 (0)