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.
This commit is contained in:
Mark Harrah 2012-11-16 09:55:48 -05:00
parent 960d17c358
commit 1bc26fa488
1 changed files with 6 additions and 1 deletions

View File

@ -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 =