Fixed: Replace java.io.File::renameTo by java.nio.file.Files::move
On Windows in EditProductContent.groovy neither file.renameTo(), Files.move()
nor FileUtils.moveFile works. Copy and delete works.
@@ -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)
}
