Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path_rename results in EINVAL instead of ENOENT when target file doesn't exist #2534

Closed
artlogic opened this issue Aug 19, 2021 · 0 comments · Fixed by #2667
Closed

path_rename results in EINVAL instead of ENOENT when target file doesn't exist #2534

artlogic opened this issue Aug 19, 2021 · 0 comments · Fixed by #2667
Assignees
Labels
bug Something isn't working priority-high High priority issue
Milestone

Comments

@artlogic
Copy link

artlogic commented Aug 19, 2021

Describe the bug

Calls to path_rename where the target file doesn't exist should result in ENOENT. Instead it results in EINVAL.

# echo "`wasmer -V` | `rustc -V` | `uname -m`"
bash: rustc: command not found
wasmer 2.0.0 |  | x86_64

Steps to reproduce

Here's a simple test program that demonstrates the issue:

#include <errno.h>
#include <stdio.h>

int main() {
  printf("ENOENT: %d\n", ENOENT);

  int r = rename("doesnotexist.txt", "doesnotexistagain.txt");
  printf("r: %d\n", r);
  printf("errno: %d\n", errno);
  perror("rename() error");
}

Output is as follows:

ENOENT: 44
r: -1
errno: 28
rename() error: Invalid argument

Expected behavior

I would expect this to result in ENOENT. The WASI docs say path_rename is "similar to renameat in POSIX". Looking at the docs for renameat and rename, the following is said:

ENOENT: The link named by oldpath does not exist; or, a directory component in newpath does not exist; or, oldpath or newpath is an empty string.
EINVAL: The new pathname contained a path prefix of the old, or, more generally, an attempt was made to make a directory a subdirectory of itself.

Actual behavior

EINVAL in the resultant error.

Note

path_unlink_file seems to suffer from the same issue - and it's possible there are several other cases I haven't stumbled into yet as well.

@artlogic artlogic added the bug Something isn't working label Aug 19, 2021
@syrusakbary syrusakbary added priority-medium Medium priority issue priority-high High priority issue and removed priority-medium Medium priority issue labels Oct 20, 2021
@Amanieu Amanieu added priority-medium Medium priority issue and removed priority-medium Medium priority issue labels Oct 20, 2021
@Amanieu Amanieu added the 🕵️ needs investigation The issue/PR needs further investigation label Nov 3, 2021
@Amanieu Amanieu added this to the v2.1 milestone Nov 3, 2021
@Amanieu Amanieu self-assigned this Nov 3, 2021
@Amanieu Amanieu removed the 🕵️ needs investigation The issue/PR needs further investigation label Nov 8, 2021
bors bot added a commit that referenced this issue Nov 8, 2021
2667: Fix error code for path_rename of a non-existant file r=ptitSeb a=Amanieu

Fixes #2534

Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
Co-authored-by: ptitSeb <sebastien.chev@gmail.com>
@bors bors bot closed this as completed in dbba897 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-high High priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants