Skip to content

FileMetadata with last modification information #463#488

Open
rcaceiro wants to merge 9 commits intoKotlin:masterfrom
rcaceiro:master
Open

FileMetadata with last modification information #463#488
rcaceiro wants to merge 9 commits intoKotlin:masterfrom
rcaceiro:master

Conversation

@rcaceiro
Copy link
Copy Markdown

Add support for file creation and modification timestamps in FileMetadata across platforms

This pull request closes issue #463

@MohammedKHC
Copy link
Copy Markdown

We can support creationTime on linux by using statx and stx_btime.
Related: square/okio#1755

@ruben-caceiro-digiwest
Copy link
Copy Markdown

Yes, POSIX support that, however the stat structure that jetbrains expose doesn't have this information.

Comment thread core/common/src/files/FileSystem.kt Outdated
Comment thread core/apple/src/files/FileSystemApple.kt Outdated
Comment thread core/common/src/files/FileSystem.kt Outdated
* Time when the file was last modified, or `null` if the filesystem does not support it.
*/
public val updatedAt: Instant? = null,
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some FSs also provide information about the last access time, does it make sense to expose it too?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcaceiro, It seems like the attribute is available in every other platform. So please add it to the metadata too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree how ever in kotlin native the struct stat don't expose both create nor modified time

@rcaceiro
Copy link
Copy Markdown
Author

@fzhinkin

Yes I can expose it no problem, I focused in add something that is needed.
Related to the experimental yes I used because the other one is deprecated ... I think as you know in 2.3 is stable and doing work for something that we have guarantee that will be removed is not a very good use of time... if as a maintainer you should update?
yes of course, but is not a me decision ... I don't know your roadmap and if is a good time to do it

@rcaceiro
Copy link
Copy Markdown
Author

Can you provide guidance about the best to do?
I do it, but is better for the maintainer provide this insight

@fzhinkin
Copy link
Copy Markdown
Collaborator

@rcaceiro, develop branch was updated to Kotlin 2.3, so now you rebase your branch and get rid of ExperimentalTime

@rcaceiro
Copy link
Copy Markdown
Author

rcaceiro commented Mar 7, 2026

@fzhinkin Ok, its done

@MohammedKHC
Copy link
Copy Markdown

Related: square/okio#1772 was merged recently, it adds creation time support for Linux and macOs.

Copy link
Copy Markdown
Collaborator

@fzhinkin fzhinkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcaceiro please make sure that all checks pass locally. You can refer https://github.com/Kotlin/kotlinx-io/blob/master/CONTRIBUTING.md#building for details.

Comment thread core/jvm/src/files/FileSystemJvm.kt Outdated
Comment thread core/nativeNonApple/src/files/FileSystemNativeNonApple.kt Outdated
Comment thread core/nodeFilesystemShared/src/node/fs.kt
Comment thread core/wasmWasi/src/files/FileSystemWasm.kt Outdated
Comment thread core/wasmWasi/src/files/FileSystemWasm.kt Outdated
Comment thread core/common/test/files/SmokeFileTest.kt Outdated
Comment thread core/common/test/files/SmokeFileTest.kt Outdated
Comment thread core/common/src/files/FileSystem.kt Outdated
* Time when the file was last modified, or `null` if the filesystem does not support it.
*/
public val updatedAt: Instant? = null,
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcaceiro, It seems like the attribute is available in every other platform. So please add it to the metadata too.

Comment thread core/apple/src/files/FileSystemApple.kt Outdated
rcaceiro and others added 4 commits March 29, 2026 09:52
Co-authored-by: Filipp Zhinkin <filipp.zhinkin@gmail.com>
Co-authored-by: Filipp Zhinkin <filipp.zhinkin@gmail.com>
Co-authored-by: Filipp Zhinkin <filipp.zhinkin@gmail.com>
@fzhinkin fzhinkin self-requested a review April 8, 2026 19:44
@fzhinkin fzhinkin self-assigned this Apr 8, 2026
@OptIn(ExperimentalForeignApi::class)
public actual val SystemTemporaryDirectory: Path
get() = Path(getenv("TMPDIR")?.toKString() ?: getenv("TMP")?.toKString() ?: "")
get() = Path(getenv("TMPDIR")?.toKString() ?: getenv("TMP")?.toKString() ?: "/tmp")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unrelated to extending file metadata.

Comment thread core/nativeNonApple/src/files/FileSystemNativeNonApple.kt Outdated
Comment thread core/nodeFilesystemShared/src/files/FileSystemNodeJs.kt Outdated
Comment thread core/nodeFilesystemShared/src/files/FileSystemNodeJs.kt
Comment thread core/common/src/files/FileSystem.kt Outdated
Comment thread core/nativeNonApple/src/files/FileSystemNativeNonApple.kt Outdated
assertFalse(fileMetadata.isDirectory)
assertTrue(fileMetadata.isRegularFile)
assertTrue(validateAt(fileMetadata.createdAt, time))
assertTrue(validateAt(fileMetadata.lastModificationTime, time))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also check that if something will be written to the filepath after this check, then the modification time will be increased, but the creation time will remain the same (assuming both times are available).

And it's worth testing that at this point they are equal to each other (they should be, right?).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve completed the tests, but I’ve noted a discrepancy on JVM Linux: createdAt matches lastModifiedAt.

According to the documentation, if the file system doesn't support a specific creation timestamp, the JVM returns a default value—typically the last-modified time. Since this is expected behavior for certain Linux environments, I propose we skip this specific check on the JVM to allow the rest of the suite to pass.

How would you like me to proceed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants