Repository: cargo-lambda/cargo-lambda (language: python)

Issue:
Cross-device link error when running cargo lambda new xxx on macos
```
❯ cargo lambda new xxx --http
Error:
  × failed to move package: from "/var/folders/_p/kwnntpkn4z50n77mtgncmft80000gn/T/.tmpRzR5LK" to "xxx"
  ╰─▶ Cross-device link (os error 18)
```

Seems to be pretty much the same as #70 . However, the fix there addresses that issue only for Linux. It should be applicable to macOS as well.



Discussion / hints:
Is there anything specific in your MacOS version that might be causing this? it's interesting that people have not bumped into it before. Which version of MacOS are you using?

Fix patch:
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 11ca843b..2d6cb897 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -63,6 +63,9 @@ jobs:
         with:
           toolchain: stable
       - uses: Swatinem/rust-cache@v1
+      - uses: actions/setup-ruby@v1
+        with:
+          ruby-version: '2.7'
 
       - name: Run integration tests
         shell: bash
diff --git a/.gitignore b/.gitignore
index 87a74b0d..a057b1cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ dist
 build
 node_modules
 .pnpm-debug.log
+test/integration
diff --git a/Cargo.lock b/Cargo.lock
index e0133eed..22e797d0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -765,7 +765,6 @@ name = "cargo-lambda-metadata"
 version = "0.10.0"
 dependencies = [
  "cargo_metadata 0.14.2",
- "libc",
  "miette",
  "remove_dir_all 0.7.0",
  "serde",
diff --git a/Cargo.toml b/Cargo.toml
index d20017f5..ad6d72ef 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,10 @@ exclude = [
     "test/fixtures/mixed-workspace-package",
     "test/fixtures/missing-binary-package",
     "test/fixtures/multi-binary-package",
-    "test/fixtures/workspace-package"
+    "test/fixtures/workspace-package",
+    "test/integration/test-fun",
+    "test/integration/test-ext",
+    "test/integration/test-logs"
 ]
 
 [profile.release]
diff --git a/Makefile b/Makefile
index 8f6cb7b9..4f1a5208 100644
--- a/Makefile
+++ b/Makefile
@@ -49,5 +49,4 @@ publish-all:
 	cd crates/cargo-lambda-cli && cargo publish
 
 run-integration: build
-	cd test/fixtures/single-binary-package && \
-	../../../target/debug/cargo-lambda lambda build
\ No newline at end of file
+	ruby test/integration.rb
\ No newline at end of file
diff --git a/crates/cargo-lambda-metadata/Cargo.toml b/crates/cargo-lambda-metadata/Cargo.toml
index e5b0dcec..64a038fc 100644
--- a/crates/cargo-lambda-metadata/Cargo.toml
+++ b/crates/cargo-lambda-metadata/Cargo.toml
@@ -18,10 +18,7 @@ rust-version = "1.59.0"
 [dependencies]
 cargo_metadata = "0.14.2"
 miette = "4.7.1"
+remove_dir_all = "0.7.0"
 serde = { version = "1.0.137", features = ["derive"] }
 serde_json = "1.0.81"
 tracing = { version = "0.1.35", features = ["log"] }
-
-[target.'cfg(target_os = "linux")'.dependencies]
-libc = "0.2.125"
-remove_dir_all = "0.7.0"
diff --git a/crates/cargo-lambda-metadata/src/fs/mod.rs b/crates/cargo-lambda-metadata/src/fs/mod.rs
index 2df67a5f..6fe37495 100644
--- a/crates/cargo-lambda-metadata/src/fs/mod.rs
+++ b/crates/cargo-lambda-metadata/src/fs/mod.rs
@@ -1,7 +1,2 @@
-#[cfg(not(target_os = "linux"))]
-pub use std::fs::rename;
-
-#[cfg(target_os = "linux")]
-mod rename_linux;
-#[cfg(target_os = "linux")]
-pub use rename_linux::*;
+mod rename;
+pub use rename::*;
diff --git a/crates/cargo-lambda-metadata/src/fs/rename_linux.rs b/crates/cargo-lambda-metadata/src/fs/rename.rs
similarity index 89%
rename from crates/cargo-lambda-metadata/src/fs/rename_linux.rs
rename to crates/cargo-lambda-metadata/src/fs/rename.rs
index 93c0cc73..25715b86 100644
--- a/crates/cargo-lambda-metadata/src/fs/rename_linux.rs
+++ b/crates/cargo-lambda-metadata/src/fs/rename.rs
@@ -35,14 +35,7 @@ where
     P: AsRef<Path>,
     Q: AsRef<Path>,
 {
-    match fs::rename(&from, &to) {
-        Ok(ok) => Ok(ok),
-        Err(e) if Some(libc::EXDEV) == e.raw_os_error() => match copy_and_delete(from, to) {
-            Ok(()) => Ok(()),
-            Err(_) => Err(e),
-        },
-        Err(e) => Err(e),
-    }
+    copy_and_delete(from, to)
 }
 
 fn copy_and_delete<P, Q>(from: P, to: Q) -> io::Result<()>


Test patch:
diff --git a/test/integration.rb b/test/integration.rb
new file mode 100644
index 00000000..aee5398b
--- /dev/null
+++ b/test/integration.rb
@@ -0,0 +1,31 @@
+require 'fileutils'
+include FileUtils
+require 'test/unit/assertions'
+include Test::Unit::Assertions
+
+BINARY = File.expand_path(File.join('target', 'debug', 'cargo-lambda'))
+BASE = File.expand_path(File.join('test', 'integration'))
+
+rm_rf BASE
+mkdir_p BASE
+
+def test_build(name, output, new_flags: '', build_flags: '')
+    cd BASE
+    system "#{BINARY} lambda new #{new_flags} #{name}"
+
+    cd name
+    system "#{BINARY} lambda build --release --quiet #{build_flags}"
+    output = File.join('target', 'lambda', output)
+    assert(File.exist?(output), "binary doesn't exist: #{output}")
+end
+
+puts "testing HTTP functions"
+test_build('test-fun', 'test-fun', new_flags: '--http')
+
+puts "testing basic extensions"
+test_build('test-ext', File.join('extensions', 'test-ext'), 
+    new_flags: '--extension', build_flags: '--extension')
+
+puts "testing logs extensions"
+test_build('test-logs', File.join('extensions', 'test-logs'), 
+    new_flags: '--extension --logs', build_flags: '--extension')