diff --git a/src/main/java/org/olat/core/commons/modules/bc/FileUploadController.java b/src/main/java/org/olat/core/commons/modules/bc/FileUploadController.java index c469faf438597f1b28000dff5dba3c3df58e1ef7..e95d89d387cb2265c49084f17ddb50f87b4f0954 100644 --- a/src/main/java/org/olat/core/commons/modules/bc/FileUploadController.java +++ b/src/main/java/org/olat/core/commons/modules/bc/FileUploadController.java @@ -74,13 +74,11 @@ import org.olat.core.util.vfs.VFSConstants; import org.olat.core.util.vfs.VFSContainer; import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSLeaf; +import org.olat.core.util.vfs.VFSManager; import org.olat.core.util.vfs.version.Versionable; import org.olat.core.util.vfs.version.Versions; import org.olat.core.util.vfs.version.VersionsManager; -import com.oreilly.servlet.multipart.DefaultFileRenamePolicy; -import com.oreilly.servlet.multipart.FileRenamePolicy; - /** * <h3>Description</h3> * <p> @@ -343,16 +341,14 @@ public class FileUploadController extends FormBasicController { // file already exists... upload anyway with new filename and // in the folder manager status. // rename file and ask user what to do - FileRenamePolicy frp = new DefaultFileRenamePolicy(); if ( ! (existingVFSItem instanceof LocalImpl)) { throw new AssertException("Can only LocalImpl VFS items, don't know what to do with file of type::" + existingVFSItem.getClass().getCanonicalName()); } - File existingFile = ((LocalImpl)existingVFSItem).getBasefile(); - File tmpOrigFilename = new File(existingFile.getAbsolutePath()); - String renamedFilename = frp.rename(tmpOrigFilename).getName(); - newFile = (VFSLeaf) uploadVFSContainer.resolve(renamedFilename); + + String renamedFilename = VFSManager.rename(uploadVFSContainer, existingVFSItem.getName()); + newFile = uploadVFSContainer.createChildLeaf(renamedFilename); + // Copy content to tmp file - InputStream in = null; BufferedOutputStream out = null; boolean success = false; @@ -608,20 +604,38 @@ public class FileUploadController extends FormBasicController { // ... and notify listeners. finishUpload(ureq); + } else if (source == revisionListDialogBox) { + removeAsListenerAndDispose(revisionListCtr); + revisionListCtr = null; + removeAsListenerAndDispose(revisionListDialogBox); + revisionListDialogBox = null; + + //remove the file + newFile.delete(); + VersionsManager.getInstance().delete(newFile, true); } else if (source == revisionListCtr) { if(FolderCommandStatus.STATUS_CANCELED == revisionListCtr.getStatus()) { revisionListDialogBox.deactivate(); + removeAsListenerAndDispose(revisionListDialogBox); + revisionListDialogBox = null; //don't want to delete revisions, clean the temporary file - newFile.delete(); - VersionsManager.getInstance().delete(newFile, true); - fireEvent(ureq, Event.CANCELLED_EVENT); + if(newFile != null) { + newFile.delete(); + VersionsManager.getInstance().delete(newFile, true); + } } else { if (existingVFSItem instanceof Versionable && ((Versionable)existingVFSItem).getVersions().isVersioned()) { revisionListDialogBox.deactivate(); - + removeAsListenerAndDispose(revisionListDialogBox); + revisionListDialogBox = null; + + if(existingVFSItem.getParentContainer() != null) { + existingVFSItem = existingVFSItem.getParentContainer().resolve(existingVFSItem.getName()); + } + Versionable versionable = (Versionable)existingVFSItem; Versions versions = versionable.getVersions(); int maxNumOfRevisions = FolderConfig.versionsAllowed(null);