[ofbiz-framework] branch trunk 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 trunk 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 trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


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

commit 2c86f9a8c0219fe8779dcb5620ee29e3efa1df86
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 f4b1fe8..e180352 100644
--- a/applications/product/groovyScripts/catalog/product/EditProductContent.groovy
+++ b/applications/product/groovyScripts/catalog/product/EditProductContent.groovy
@@ -113,8 +113,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)
@@ -138,8 +138,9 @@ if (fileType) {
             } catch (Exception e) {
                 logError(e, "error deleting existing file (not neccessarily a problem)")
             }
-            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) {
             logError(e, module)
         }