Skip to content
Browse files

When preserving last modified, convert negative values to 0

File.lastModified can return a negative number, but File.setLastModified doesn't accept
negative numbers.  See Java bug #6791812.
  • Loading branch information...
1 parent 960d17c commit 1bc26fa488c774a07a4f5a687adb91ada38797e9 @harrah committed Nov 16, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 util/io/IO.scala
View
7 util/io/IO.scala
@@ -566,7 +566,12 @@ object IO
if(preserveLastModified)
copyLastModified(sourceFile, targetFile)
}
- def copyLastModified(sourceFile: File, targetFile: File) = targetFile.setLastModified( sourceFile.lastModified )
+ def copyLastModified(sourceFile: File, targetFile: File) = {
+ val last = sourceFile.lastModified
+ // lastModified can return a negative number, but setLastModified doesn't accept it
+ // see Java bug #6791812
+ targetFile.setLastModified( math.max(last, 0L) )
+ }
def defaultCharset = utf8
def write(file: File, content: String, charset: Charset = defaultCharset, append: Boolean = false): Unit =

0 comments on commit 1bc26fa

Please sign in to comment.
Something went wrong with that request. Please try again.