mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8341881: [REDO] java/nio/file/attribute/BasicFileAttributeView/CreationTime.java#tmp fails on alinux3
8342145: File libCreationTimeHelper.c compile fails on Alpine
Reviewed-by: sgehwolf, goetz, phh
Backport-of: daa67f45f0
This commit is contained in:
committed by
Sergey Shelomentsev
parent
0aba73d012
commit
283b04ec2c
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@@ -28,7 +29,7 @@
|
||||
* @library ../.. /test/lib
|
||||
* @build jdk.test.lib.Platform
|
||||
* @comment We see this failing with "UnsatisfiedLinkError: Native Library ...libCreationTimeHelper.so already loaded in another classloader". Thus run as othervm
|
||||
* @run main/othervm CreationTime
|
||||
* @run main/othervm/native CreationTime
|
||||
*/
|
||||
|
||||
/* @test id=cwd
|
||||
@@ -37,7 +38,7 @@
|
||||
* scratch directory maybe at diff disk partition to /tmp on linux.
|
||||
* @library ../.. /test/lib
|
||||
* @build jdk.test.lib.Platform
|
||||
* @run main/native CreationTime .
|
||||
* @run main/othervm/native CreationTime .
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
@@ -51,8 +52,6 @@ import jtreg.SkippedException;
|
||||
|
||||
public class CreationTime {
|
||||
|
||||
private static final java.io.PrintStream err = System.err;
|
||||
|
||||
/**
|
||||
* Reads the creationTime attribute
|
||||
*/
|
||||
@@ -78,14 +77,9 @@ public class CreationTime {
|
||||
FileTime creationTime = creationTime(file);
|
||||
Instant now = Instant.now();
|
||||
if (Math.abs(creationTime.toMillis()-now.toEpochMilli()) > 10000L) {
|
||||
System.out.println("creationTime.toMillis() == " + creationTime.toMillis());
|
||||
// If the file system doesn't support birth time, then skip this test
|
||||
if (creationTime.toMillis() == 0) {
|
||||
throw new SkippedException("birth time not support for: " + file);
|
||||
} else {
|
||||
err.println("File creation time reported as: " + creationTime);
|
||||
throw new RuntimeException("Expected to be close to: " + now);
|
||||
}
|
||||
System.err.println("creationTime.toMillis() == " + creationTime.toMillis());
|
||||
System.err.println("File creation time reported as: " + creationTime);
|
||||
throw new RuntimeException("Expected to be close to: " + now);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +101,12 @@ public class CreationTime {
|
||||
}
|
||||
} else if (Platform.isLinux()) {
|
||||
// Creation time read depends on statx system call support
|
||||
supportsCreationTimeRead = CreationTimeHelper.linuxIsCreationTimeSupported();
|
||||
try {
|
||||
supportsCreationTimeRead = CreationTimeHelper.
|
||||
linuxIsCreationTimeSupported(file.toAbsolutePath().toString());
|
||||
} catch (Throwable e) {
|
||||
supportsCreationTimeRead = false;
|
||||
}
|
||||
// Creation time updates are not supported on Linux
|
||||
supportsCreationTimeWrite = false;
|
||||
}
|
||||
@@ -122,8 +121,11 @@ public class CreationTime {
|
||||
Instant plusHour = Instant.now().plusSeconds(60L * 60L);
|
||||
Files.setLastModifiedTime(file, FileTime.from(plusHour));
|
||||
FileTime current = creationTime(file);
|
||||
if (!current.equals(creationTime))
|
||||
if (!current.equals(creationTime)) {
|
||||
System.err.println("current = " + current);
|
||||
System.err.println("creationTime = " + creationTime);
|
||||
throw new RuntimeException("Creation time should not have changed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Red Hat, Inc.
|
||||
* Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@@ -20,6 +21,7 @@
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
public class CreationTimeHelper {
|
||||
|
||||
static {
|
||||
@@ -27,5 +29,5 @@ public class CreationTimeHelper {
|
||||
}
|
||||
|
||||
// Helper so as to determine 'statx' support on the runtime system
|
||||
static native boolean linuxIsCreationTimeSupported();
|
||||
static native boolean linuxIsCreationTimeSupported(String file);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Red Hat, Inc.
|
||||
* Copyright (c) 2024 Alibaba Group Holding Limited. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@@ -21,17 +22,120 @@
|
||||
* questions.
|
||||
*/
|
||||
#include "jni.h"
|
||||
#include <stdbool.h>
|
||||
#if defined(__linux__)
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dlfcn.h>
|
||||
#ifndef STATX_BASIC_STATS
|
||||
#define STATX_BASIC_STATS 0x000007ffU
|
||||
#endif
|
||||
#ifndef STATX_BTIME
|
||||
#define STATX_BTIME 0x00000800U
|
||||
#endif
|
||||
#ifndef RTLD_DEFAULT
|
||||
#define RTLD_DEFAULT RTLD_LOCAL
|
||||
#endif
|
||||
#ifndef AT_SYMLINK_NOFOLLOW
|
||||
#define AT_SYMLINK_NOFOLLOW 0x100
|
||||
#endif
|
||||
#ifndef AT_FDCWD
|
||||
#define AT_FDCWD -100
|
||||
#endif
|
||||
|
||||
#ifndef __GLIBC__
|
||||
// Alpine doesn't know these types, define them
|
||||
typedef unsigned int __uint32_t;
|
||||
typedef unsigned short __uint16_t;
|
||||
typedef unsigned long int __uint64_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Timestamp structure for the timestamps in struct statx.
|
||||
*/
|
||||
struct my_statx_timestamp {
|
||||
int64_t tv_sec;
|
||||
__uint32_t tv_nsec;
|
||||
int32_t __reserved;
|
||||
};
|
||||
|
||||
/*
|
||||
* struct statx used by statx system call on >= glibc 2.28
|
||||
* systems
|
||||
*/
|
||||
struct my_statx
|
||||
{
|
||||
__uint32_t stx_mask;
|
||||
__uint32_t stx_blksize;
|
||||
__uint64_t stx_attributes;
|
||||
__uint32_t stx_nlink;
|
||||
__uint32_t stx_uid;
|
||||
__uint32_t stx_gid;
|
||||
__uint16_t stx_mode;
|
||||
__uint16_t __statx_pad1[1];
|
||||
__uint64_t stx_ino;
|
||||
__uint64_t stx_size;
|
||||
__uint64_t stx_blocks;
|
||||
__uint64_t stx_attributes_mask;
|
||||
struct my_statx_timestamp stx_atime;
|
||||
struct my_statx_timestamp stx_btime;
|
||||
struct my_statx_timestamp stx_ctime;
|
||||
struct my_statx_timestamp stx_mtime;
|
||||
__uint32_t stx_rdev_major;
|
||||
__uint32_t stx_rdev_minor;
|
||||
__uint32_t stx_dev_major;
|
||||
__uint32_t stx_dev_minor;
|
||||
__uint64_t __statx_pad2[14];
|
||||
};
|
||||
|
||||
typedef int statx_func(int dirfd, const char *restrict pathname, int flags,
|
||||
unsigned int mask, struct my_statx *restrict statxbuf);
|
||||
|
||||
static statx_func* my_statx_func = NULL;
|
||||
#endif //#defined(__linux__)
|
||||
|
||||
// static native boolean linuxIsCreationTimeSupported()
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_CreationTimeHelper_linuxIsCreationTimeSupported(JNIEnv *env, jclass cls)
|
||||
{
|
||||
Java_CreationTimeHelper_linuxIsCreationTimeSupported(JNIEnv *env, jclass cls, jstring file) {
|
||||
#if defined(__linux__)
|
||||
void* statx_func = dlsym(RTLD_DEFAULT, "statx");
|
||||
return statx_func != NULL ? JNI_TRUE : JNI_FALSE;
|
||||
struct my_statx stx = {0};
|
||||
int ret, atflag = AT_SYMLINK_NOFOLLOW;
|
||||
unsigned int mask = STATX_BASIC_STATS | STATX_BTIME;
|
||||
|
||||
my_statx_func = (statx_func*) dlsym(RTLD_DEFAULT, "statx");
|
||||
if (my_statx_func == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file == NULL) {
|
||||
printf("input file error!\n");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
const char *utfChars = (*env)->GetStringUTFChars(env, file, NULL);
|
||||
if (utfChars == NULL) {
|
||||
printf("jstring convert to char array error!\n");
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
ret = my_statx_func(AT_FDCWD, utfChars, atflag, mask, &stx);
|
||||
|
||||
if (file != NULL && utfChars != NULL) {
|
||||
(*env)->ReleaseStringUTFChars(env, file, utfChars);
|
||||
}
|
||||
|
||||
if (ret != 0) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
// On some systems where statx is available but birth time might still not
|
||||
// be supported as it's file system specific. The only reliable way to
|
||||
// check for supported or not is looking at the filled in STATX_BTIME bit
|
||||
// in the returned statx buffer mask.
|
||||
if ((stx.stx_mask & STATX_BTIME) != 0)
|
||||
return JNI_TRUE;
|
||||
return JNI_FALSE;
|
||||
#else
|
||||
return JNI_FALSE;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user