Skip to content

Error remove dir ? #4280

Open
Open
@orangeC23

Description

@orangeC23

Steps to Reproduce

(1) The cfile is :

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>

int path_remove_directory(int basedir_fd, const char *file_name) {
    printf("Enter path_remove_directory.\n");

    if (unlinkat(basedir_fd, file_name, AT_REMOVEDIR) == -1) {
        perror("Error deleting file");
        close(basedir_fd);
        return 1;
    }

    printf("File deleted successfully.\n");
    printf("Leave path_remove_directory.\n");
    return basedir_fd;
}

int snapshot(int myfd){   
    printf("Enter snapshot\n");
    
    struct stat file_info;
    if (fstat(myfd, &file_info) == -1) {
        perror("Error getting file attributes");
        close(myfd);
        return 1;
    }

    printf("File Size: %lld bytes \n", (long long)file_info.st_size);
    
    if (close(myfd) == -1) {
        perror("Error closing file");
        return 1;
    }

    printf("Leave snapshot\n");
    return 0;
}

int get_fd(const char* file_name, int open_style){\
    int fd = open(file_name, open_style);
    if (fd == -1) {
        perror("Failed to open the file");
        return 1;
    }

    return fd;
}

int path_remove_directory9G1oIUB6Wo(int fd) {
    const char *file_name = "tmpdir"; // Replace with the file's name
    return path_remove_directory(fd, file_name);
}


int main() {
    const char* file_name = "Data";
    int open_style= O_RDWR;
    int fd = get_fd(file_name, open_style);
    path_remove_directory9G1oIUB6Wo(fd);
    snapshot(fd);
    return 0;
}

(2)compile the c file into wasm: ./wasi-sdk-16.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-16.0/share/wasi-sysroot remove.c -o remove.wasm
(3)exeute remove.wasm
wasmer run --dir=./Data remove.wasm

Expected Results

wasmtime,wamr,wasmedge,wazero executing remove.wasm file print:

Failed to open the file: Is a directory
Enter path_remove_directory.
Error deleting file: Not a directory
Error getting file attributes: Bad file descriptor

And using gcc remove.c -o remove and execute ./remove also prints the above result.
And the tmpdir id not removed.

Actual Results

wasmer prints:

Enter path_remove_directory.
File deleted successfully.
Leave path_remove_directory.
Enter snapshot
File Size: 4096 bytes 
Leave snapshot

And tmpdir is removed.
I'm not sure whether this is a bug. Maybe I made a mistake.

Versions and Environment

wasmer 4.2.2
Operating system: Ubuntu 20.04

Architecture: x86_64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions