Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-159692

DDMUserPersonalFolderUploadFileEntryHandler mixes repository ids leaving it unable to generate a unique name

Description

    In tracing a failure that was not being logged (see https://issues.liferay.com/browse/LPS-159225), we were able to determine that a DuplicateFileNameException was being thrown when trying to upload the file.

    In reviewing DDMUserPersonalFolderUploadFileEntryHandler class where the DuplicateFileNameException was being generated, we can see an attempt to generate a unique filename for the current upload in https://github.com/liferay/liferay-portal/blob/master/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-web/src/main/java/com/liferay/dynamic/data/mapping/form/web/internal/upload/DDMUserPersonalFolderUploadFileEntryHandler.java#L84-L87

    As can be seen in this call, the _exists() method is being called passing in the scope group ID, folder ID and filename to the method. The _exists() method will look for a file in the repository id for the group id, and the folder and the filename. If it finds an existing file, _exists() returns true, otherwise it returns false.

    Unfortunately this causes a problem because the repository id is being passed into the upload portlet request, see https://github.com/liferay/liferay-portal/blob/master/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-web/src/main/java/com/liferay/dynamic/data/mapping/form/web/internal/upload/DDMUserPersonalFolderUploadFileEntryHandler.java#L82-L83

    And this repository id is used in the addFileEntry() call to store the file, see https://github.com/liferay/liferay-portal/blob/master/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-web/src/main/java/com/liferay/dynamic/data/mapping/form/web/internal/upload/DDMUserPersonalFolderUploadFileEntryHandler.java#L89-L95

    Because the _exists() method is given the scope group id, the repository id the system uses to determine if the file exists is actually different than the repository id used to add the file.

    So _exists() returns false for a filename that has already been uploaded because it doesn't find the file in the alternate location, but when the addFileEntry() is called with the different repository id, it tries then to upload using a duplicate filename and throws the DuplicateFilenameException and fails.

    Steps to reproduce:

    1. Create a form that includes a document upload.
    2. Complete the form and upload any file such as "readme.txt".
    3. Complete the form and re-upload the same file.

    Expected result: The 2nd upload would rename the file as "readme (2).txt" and the upload would be successful.
    Actual result: The 2nd upload fails, the UI shows a generic "your request failed message", there's nothing in the logs to indicate the failure and you're prevented from completing the form.

    This is a problem since different users will not know what filenames have been used by others during uploads and there is a high probability that there will be filename conflicts during the upload.

    Attachments

      Issue Links

        Activity

          People

            andre.farias André Farias
            david.nebinger David Nebinger
            Rafaela Nascimento Rafaela Nascimento
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              31 weeks, 2 days ago

              Packages

                Version Package
                7.4.13 DXP U56
                Master