wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

`wasmer publish` bugs out when adding bindings to the wapm package

Open ayys opened this issue 1 year ago • 0 comments

Describe the bug

wasmer publish bugs out when adding bindings to the wapm package.

Steps to reproduce

Download the tarball - polyvalid.tar.gz

tar xvf polyvalid.tar.gz
cd polyvalid
wasmer publish --dry-run
error: Unable to load the bindings for "polyvalid" because "/Users/ayushjha/code/wapm/polyvalid/Users/ayushjha/code/wapm/polyvalid/polyvalid.wai" doesn't exist

Expected behavior

Be able to successfully publish this package

Actual behavior

Fails to publish because it cannot properly discern the path of polyvalid.wai.

Additional context

wasmer -vV

wasmer 3.2.0-beta.1 (82974ac 2023-03-23)
binary: wasmer-cli
commit-hash: 82974aca26b7d0a0a6f19f62a39a1d2ad07bdfad
commit-date: 2023-03-23
host: aarch64-apple-darwin
compiler: singlepass,cranelift

Looks like it could be an issue with the way wasmer adds files to tar.gz

diff --git a/lib/cli/src/commands/publish.rs b/lib/cli/src/commands/publish.rs
index 192db4e0cb..028f6c40d6 100644
--- a/lib/cli/src/commands/publish.rs
+++ b/lib/cli/src/commands/publish.rs
@@ -242,12 +242,18 @@ fn append_path_to_tar_gz(
     base_path: &Path,
     target_path: &Path,
 ) -> Result<PathBuf, (PathBuf, io::Error)> {
-    let normalized_path = normalize_path(base_path, target_path);
+    // if the target path is absolute, remove the base from it:
+    let relative_target_path = if target_path.is_absolute() {
+        target_path.strip_prefix(base_path).unwrap_or(target_path)
+    } else {
+        target_path
+    };
+    let normalized_path = normalize_path(base_path, relative_target_path);
     normalized_path
         .metadata()
         .map_err(|e| (normalized_path.clone(), e))?;
     builder
-        .append_path_with_name(&normalized_path, target_path)
+        .append_path_with_name(&normalized_path, relative_target_path)
         .map_err(|e| (normalized_path.clone(), e))?;
     Ok(normalized_path)
 }

ayys avatar Mar 26 '23 12:03 ayys