[ofbiz-framework] branch release18.12 updated: Fixed: Replace java.io.File::renameTo by java.nio.file.Files::move (OFBIZ-12063)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch release18.12 updated: Fixed: Replace java.io.File::renameTo by java.nio.file.Files::move (OFBIZ-12063)

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/release18.12 by this push:
     new 41faac6  Fixed: Replace java.io.File::renameTo by java.nio.file.Files::move (OFBIZ-12063)
41faac6 is described below

commit 41faac6a3c14fab6f90d792a4c7bb7d789eb7d94
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Fri Nov 27 10:20:57 2020 +0100

    Fixed: Replace java.io.File::renameTo by java.nio.file.Files::move (OFBIZ-12063)
   
    On Windows in EditProductContent.groovy neither file.renameTo(), Files.move()
    nor FileUtils.moveFile works. Copy and delete works.
---
 .../groovyScripts/catalog/product/EditProductContent.groovy      | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/applications/product/groovyScripts/catalog/product/EditProductContent.groovy b/applications/product/groovyScripts/catalog/product/EditProductContent.groovy
index 938687b..4a43c25 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 {
-            file = new File(imageServerPath + "/" + filePathPrefix, defaultFileName)
-            file1 = new File(imageServerPath + "/" + filePathPrefix, filenameToUse)
+            defaultFile = new File(imageServerPath + "/" + filePathPrefix, defaultFileName)
+            fileToUse = new File(imageServerPath + "/" + filePathPrefix, filenameToUse)
             try {
                 // Delete existing image files
                 File targetDir = new File(imageServerPath + "/" + filePathPrefix)
@@ -140,8 +140,9 @@ if (fileType) {
             } catch (Exception e) {
                 Debug.logError(e, "error deleting existing file (not neccessarily a problem)", module)
             }
-            Path source = file.toPath()
-            Files.move(source, source.resolveSibling(filenameToUse))
+            // 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();
         } catch (Exception e) {
             Debug.logError(e, module)
         }