Skip to content

Commit

Permalink
Fix: Don't set times that are epoch when copying/moving
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Apr 16, 2024
1 parent 1ad41c4 commit 9dc02ba
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import java8.nio.file.StandardCopyOption
import java8.nio.file.StandardOpenOption
import java8.nio.file.attribute.BasicFileAttributeView
import java8.nio.file.attribute.BasicFileAttributes
import java8.nio.file.attribute.FileTime
import java.io.IOException

internal object ForeignCopyMove {
Expand Down Expand Up @@ -102,12 +103,17 @@ internal object ForeignCopyMove {
// now on.
val targetAttributeView = target.getFileAttributeView(BasicFileAttributeView::class.java)!!
val lastModifiedTime = sourceAttributes.lastModifiedTime()
.takeIf { it != FileTime::class.EPOCH }
val lastAccessTime = if (copyOptions.copyAttributes) {
sourceAttributes.lastAccessTime()
sourceAttributes.lastAccessTime().takeIf { it != FileTime::class.EPOCH }
} else {
null
}
val creationTime = if (copyOptions.copyAttributes) {
sourceAttributes.creationTime().takeIf { it != FileTime::class.EPOCH }
} else {
null
}
val creationTime = if (copyOptions.copyAttributes) sourceAttributes.creationTime() else null
try {
targetAttributeView.setTimes(lastModifiedTime, lastAccessTime, creationTime)
} catch (e: IOException) {
Expand Down

0 comments on commit 9dc02ba

Please sign in to comment.