Skip to content

Commit

Permalink
8316304: (fs) Add support for BasicFileAttributes.creationTime() for …
Browse files Browse the repository at this point in the history
…Linux

Reviewed-by: stuefe, alanb, bpb, mli
  • Loading branch information
jerboaa authored and pull[bot] committed Apr 25, 2024
1 parent 4c3f080 commit 8303465
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 16 deletions.
16 changes: 11 additions & 5 deletions src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. 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
Expand All @@ -25,10 +25,15 @@

package sun.nio.fs;

import java.nio.file.attribute.*;
import java.util.concurrent.TimeUnit;
import java.util.Set;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.GroupPrincipal;
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.UserPrincipal;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
* Unix implementation of PosixFileAttributes.
Expand All @@ -52,6 +57,7 @@ class UnixFileAttributes
private long st_ctime_sec;
private long st_ctime_nsec;
private long st_birthtime_sec;
private long st_birthtime_nsec;

// created lazily
private volatile UserPrincipal owner;
Expand Down Expand Up @@ -158,7 +164,7 @@ public FileTime lastAccessTime() {
@Override
public FileTime creationTime() {
if (UnixNativeDispatcher.birthtimeSupported()) {
return FileTime.from(st_birthtime_sec, TimeUnit.SECONDS);
return toFileTime(st_birthtime_sec, st_birthtime_nsec);
} else {
// return last modified when birth time not supported
return lastModifiedTime();
Expand Down
Loading

0 comments on commit 8303465

Please sign in to comment.