You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2020/11/27 10:55:23 UTC

[ofbiz-framework] 01/02: Reverted: Replace java.io.File::renameTo by java.nio.file.Files::move (OFBIZ-12063)

This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release17.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 7400899b58b5d1ce84fd175093bc1349160f27a1
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Fri Nov 27 11:47:57 2020 +0100

    Reverted: Replace java.io.File::renameTo by java.nio.file.Files::move (OFBIZ-12063)
    
    This reverts commit 2c86f9a8c0219fe8779dcb5620ee29e3efa1df86.
    
    Actually the problem was due to another WIP where 2 streams were not closed
---
 .../groovyScripts/catalog/product/EditProductContent.groovy      | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/applications/product/groovyScripts/catalog/product/EditProductContent.groovy b/applications/product/groovyScripts/catalog/product/EditProductContent.groovy
index 4a43c25..938687b 100644
--- a/applications/product/groovyScripts/catalog/product/EditProductContent.groovy
+++ b/applications/product/groovyScripts/catalog/product/EditProductContent.groovy
@@ -115,8 +115,8 @@ if (fileType) {
         imageUrl = imageUrlPrefix + "/" + filePathPrefix + java.net.URLEncoder.encode(filenameToUse, characterEncoding)
 
         try {
-            defaultFile = new File(imageServerPath + "/" + filePathPrefix, defaultFileName)
-            fileToUse = new File(imageServerPath + "/" + filePathPrefix, filenameToUse)
+            file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName)
+            file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse)
             try {
                 // Delete existing image files
                 File targetDir = new File(imageServerPath + "/" + filePathPrefix)
@@ -140,9 +140,8 @@ if (fileType) {
             } catch (Exception e) {
                 Debug.logError(e, "error deleting existing file (not neccessarily a problem)", module)
             }
-            // OFBIZ-12063: on Windows neither file.renameTo(), Files.move() nor FileUtils.moveFile() works
-            Files.copy(defaultFile.toPath(), fileToUse.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING)
-            defaultFile.delete();
+            Path source = file.toPath()
+            Files.move(source, source.resolveSibling(filenameToUse))
         } catch (Exception e) {
             Debug.logError(e, module)
         }