You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Dirk Heinrichs (Jira)" <ji...@apache.org> on 2021/03/15 09:34:00 UTC

[jira] [Comment Edited] (IO-721) FileUtils.copyDirectory() tries to set last modified on source dir after update to 2.8.0

    [ https://issues.apache.org/jira/browse/IO-721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17301535#comment-17301535 ] 

Dirk Heinrichs edited comment on IO-721 at 3/15/21, 9:33 AM:
-------------------------------------------------------------

Looking at the code I see that doCopyDirectory() calls a new method FileUtils.setLastModified() in 2.8.0 which throws an exception (with a wrong message, BTW.):
{code:java}
    private static void setLastModified(final File sourceFile, final File targetFile) throws IOException {
        if (!targetFile.setLastModified(sourceFile.lastModified())) {
            throw new IOException("Failed setLastModified on " + sourceFile);
        }
    }
{code}
while in 2.7 it calls "destFile.setLastModified()" directly w/o throwing an exception. If that isn't an obvious issue...


was (Author: heinrichs):
Looking at the code I see that doCopyDirectory() calls a new method FileUtils.setLastModified() in 2.8.0 which throws an exception (with a wrong message, BTW.)
{code:java}
    private static void setLastModified(final File sourceFile, final File targetFile) throws IOException {
        if (!targetFile.setLastModified(sourceFile.lastModified())) {
            throw new IOException("Failed setLastModified on " + sourceFile);
        }
    }
{code}
while in 2.7 it calls "destFile.setLastModified()" directly w/o throwing an exception. If that isn't an obvious issue...

> FileUtils.copyDirectory() tries to set last modified on source dir after update to 2.8.0
> ----------------------------------------------------------------------------------------
>
>                 Key: IO-721
>                 URL: https://issues.apache.org/jira/browse/IO-721
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.8.0
>         Environment: Ubuntu 20.04 LTS
> Groovy 3.0.x
> Java 11 (from Ubuntu packages)
>            Reporter: Dirk Heinrichs
>            Priority: Major
>
> A simple
> {code:java}
> FileUtils.copyDirectory(source, dest, glob) {code}
> works fine when using Commons-IO 2.7, but fails with
> {code:java}
> Caught: java.io.IOException: Failed setLastModified on /path/to/source
> java.io.IOException: Failed setLastModified on /path/to/source
>         at org.apache.commons.io.FileUtils.setLastModified(FileUtils.java:2561)
>         at org.apache.commons.io.FileUtils.doCopyDirectory(FileUtils.java:1361)
>         at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:733)
>         at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:659)
>         at org.apache.commons.io.FileUtils.copyDirectory(FileUtils.java:606)
> {code}
> after update to 2.8.0. From reading the documentation, it's also my understanding that "setLastModified()" should be executed on "dest" to set the same modification time as "source", but *not* on "source".



--
This message was sent by Atlassian Jira
(v8.3.4#803005)