You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jochen Wiedmann (JIRA)" <ji...@apache.org> on 2019/02/23 15:56:00 UTC

[jira] [Commented] (FILEUPLOAD-293) FileExistsException: Destination .. already exists when DiskFileItem.write was given an existing file

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

Jochen Wiedmann commented on FILEUPLOAD-293:
--------------------------------------------

Trying to reproduce the problem with the code below. Works fine, so please help me by telling me what you are doing different:

 

 

{{ @Test}}
{{ public void testMoveFile() throws Exception {}}
{{    final String content = }}
{{        "-----1234\r\n" +}}
{{        "Content-Disposition: form-data; name=\"file\";"}}
{{            + "filename=\"foo.tab\"\r\n" +}}
{{        "Content-Type: text/whatever\r\n" +}}
{{        "\r\n" +}}
{{        "This is the content of the file\n" +}}
{{        "\r\n" +}}
{{        "-----1234--\r\n";}}
{{    final byte[] contentBytes = content.getBytes("US-ASCII");}}
{{    final HttpServletRequest request = new}}

{{        MockHttpServletRequest(contentBytes, Constants.CONTENT_TYPE);}}
{{    final List<FileItem> items = upload.parseRequest(request);}}
{{    assertNotNull(items);}}
{{    assertFalse(items.isEmpty());}}
{{    final DiskFileItem dfi = (DiskFileItem) items.get(0);}}
{{    final File out = new File("target/unit-tests/DiskFileUpload");}}
{{    final File outDir = out.getParentFile();}}
{{    if (!outDir.isDirectory()) {}}
{{        outDir.mkdirs();}}
{{    }}}
{{    dfi.write(out);}}
{{ }}}

 

> FileExistsException: Destination .. already exists when DiskFileItem.write was given an existing file
> -----------------------------------------------------------------------------------------------------
>
>                 Key: FILEUPLOAD-293
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-293
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Mladen Girazovski
>            Priority: Major
>
> Since 1.4, where FILEUPLOAD-248 was shipped, passing an existing file to DiskFileItem.write will cause an FileExistsException with the message "Destination FILE already exist", this prevents us from upgrading to 1.4 from 1.3.3.
>  
> {{2019-02-20 01:12:56,504 http-nio-2990-exec-3 ERROR [|5ccb9b99-a96f-42ba-ad01-ac278516e1a4|] [IssueAttachmentsResource.privacy-safe] Error saving attachment}}
> {{org.apache.commons.io.FileExistsException: Destination '/buildeng/bamboo-agent-home/xml-data/build-dir/CLOUDRELEASE-AGILEWD15421-FT18/jira-test-runner-jira/target/cargo/configurations/tomcat9x/temp/attachment-3404789743778163937.tmp' already exists}}
> {{ at org.apache.commons.io.FileUtils.moveFile(FileUtils.java:3001)}}
> {{ at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:405)}}
> {{ at com.atlassian.plugins.rest.common.multipart.fileupload.CommonsFileUploadFilePart.write(CommonsFileUploadFilePart.java:49)}}
> {{ at com.atlassian.jira.rest.v2.issue.IssueAttachmentsResource.getFileFromFilePart(IssueAttachmentsResource.java:175)}}
> {{...}}
>  
> Apache Felix also ran into the same bug:
> https://issues.apache.org/jira/browse/FELIX-6037 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)