wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

Fail to set the file time.

Open Userzxcvbvnm opened this issue 7 months ago • 0 comments

Describe the bug

Does not set time as expected.

Steps to reproduce

(1)The test case is :


#define _XOPEN_SOURCE 700

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


void path_filestat_set_times_00027_WD7wr(int fd, const char *pathname) {

    printf("Enter function path_filestat_set_times_00027_WD7wr\n");

    struct timespec times[2] = {{946684800, 0}, {946684800, 0}}; // Set times to year 2000

    
    if (utimensat(AT_FDCWD, "subfile_1", times, AT_SYMLINK_FOLLOW) == 0) {

        printf("Timestamps adjusted successfully\n");

        struct stat statbuf;
        if (fstat(fd, &statbuf) == -1) {
            printf("Failed to get file status\n");
            return;
        }

        printf("File timestamps after adjustment:\n");
        printf("Last access time: %ld\n", statbuf.st_atime);
        printf("Last modification time: %ld\n", statbuf.st_mtime);
    } else {
        printf("Failed to adjust timestamps\n");
    }
}

int get_fd(const char *filename, int flags) {
    int fd = open(filename, flags);
    
    if (fd == -1) {
        printf("Get file descriptor of file %s failed!\n", filename);
        return -1;
    } else {
        printf("Get file descriptor of file %s succeed!\n", filename);
        return fd;
    }
}

void closebyfd(int fd) {
    if (close(fd) == -1) {
        printf("Close the file %d by descriptor failed!\n", fd);
    }
}

int main() {
    int fd = get_fd("subfile_1", O_RDWR | O_CREAT);
    if (fd == -1) {
        return -1;
    }

    
    path_filestat_set_times_00027_WD7wr(fd, "subfile_1");


    closebyfd(fd);

    return 0;
}


(2)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm

(3)Running wasm: (Before run the Wasm file, file subfile_1 exists.) wasmer run --dir=. test.wasm

Expected behavior

print:

Get file descriptor of file subfile_1 succeed!
Enter function path_filestat_set_times_00027_WD7wr
Timestamps adjusted successfully
File timestamps after adjustment:
Last access time: 946684800
Last modification time: 946684800

And this is what WAMR, wasmtime and WasmEdge do.

Actual behavior

wasmer print:

Get file descriptor of file subfile_1 succeed!
Enter function path_filestat_set_times_00027_WD7wr
Timestamps adjusted successfully
File timestamps after adjustment:
Last access time: 1719396243
Last modification time: 1719396243

wasmer does not set the time as expected.

Additional context

Ubuntu 20.04 x86_64 wasmer-4.3.1 and wasmer-4.2.2

Userzxcvbvnm avatar Jun 26 '24 10:06 Userzxcvbvnm