When deleteSourceFiles is true, the setPermissions method of FileWritingMessageHandler should be called.
Expected Behavior
chmod should need to work when the FileWritingMessageHandler's deleteSourceFiles property is true. Current Behavior
When the deleteSourceFiles property of FileWritingMessageHandler is true, chmod does not work. Context
My code is as follows:
@Bean
public IntegrationFlow pacToZipFlow(MessageChannel packToZipChannel, FileSynchronizerProperties fileSynchronizerProperties) {
return IntegrationFlow
.from(packToZipChannel)
.transformWith(transformer -> transformer.transformer(new ZipTransformer()))
.handle(Files
.outboundAdapter(new File(fileSynchronizerProperties.outputDirectory()))
.fileNameGenerator(message -> System.currentTimeMillis() + FileConsts.ZIP_FILE_SUFFIX)
.deleteSourceFiles(true)
.chmod(0700)
)
.get();
}
When deleteSourceFiles is true, the setPermissions(resultFile) method is not called in the handleFileMessage method of FileWritingMessageHandler.
The logic is like this:
if (this.deleteSourceFiles && originalFile != null && !originalFile.delete()) {
throw new IllegalStateException("Could not delete original file: " + originalFile);
}
setPermissions(resultFile);
}
/**
* Set permissions on newly written files.
* @param resultFile the file.
* @throws IOException any exception.
* @since 5.0
*/
protected void setPermissions(File resultFile) throws IOException {
That setPermissions is for a newly created file.
It has nothing to do with original which you are going to delete.
As you see that setPermissions() is not called only in case of original file delete failure.
Do you mean the setPermissions() has to be unconditional?
Or what is your request about, please?
When I call the handleFileMessage() method, and !FileExistsMode.APPEND.equals(this.fileExistsMode) && this.deleteSourceFiles is true, the rename() method is called directly without calling the setPermissions() method. Can you provide support for this?
private File handleFileMessage(File sourceFile, File tempFile, File resultFile, Message<?> requestMessage)
throws IOException {
if (!FileExistsMode.APPEND.equals(this.fileExistsMode) && this.deleteSourceFiles) {
rename(sourceFile, resultFile);
return resultFile;
}
else {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(sourceFile));
return handleInputStreamMessage(bis, sourceFile, tempFile, resultFile, requestMessage);
}
}
Yeah... That use-case is missed. Good catch!
I can fix it quickly, but wonder if you are willing to contribute: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc.
Looks like that setPermissions() is supposed to be called after rename().