LPS-46553 After upgrade to 6.2, Liferay Sync has problems when DL contains preexisting documents with reserved names

Same pull than https://github.com/sergiogonzalez/liferay-portal/pull/1395 but changing "do...while" with standard while.

IMPORTANT: This pull request depends on changes made by following pull: https://github.com/sergiogonzalez/liferay-portal/pull/1383 (LPS-46168) do not merge until this LPS is closed.