Skip to content

Commit

Permalink
GH-9294: Set permissions to target file on rename
Browse files Browse the repository at this point in the history
* GH-9294: Set permissions to target file on rename

Fixes: #9294

When the `deleteSourceFiles` property of `FileWritingMessageHandler` is `true`, the `chmod` is not set on the target file.

* Fix `FileWritingMessageHandler.handleFileMessage()` logic to `setPermissions(resultFile)` after `move` operation

* * Set only `OWNER_READ` permission for file in unit test

(cherry picked from commit 3e71ea5)
  • Loading branch information
artembilan authored and spring-builds committed Jul 8, 2024
1 parent 89425f0 commit bd2cf77
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ private File handleFileMessage(File sourceFile, File tempFile, File resultFile,

if (!FileExistsMode.APPEND.equals(this.fileExistsMode) && this.deleteSourceFiles) {
rename(sourceFile, resultFile);
setPermissions(resultFile);
return resultFile;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import org.springframework.beans.DirectFieldAccessor;
Expand Down Expand Up @@ -301,6 +303,23 @@ public void deleteFilesTrueWithFilePayload() throws Exception {
assertThat(sourceFile.exists()).isFalse();
}

@Test
@DisabledOnOs(OS.WINDOWS)
public void deleteFilesWithChmod() throws Exception {
QueueChannel output = new QueueChannel();
handler.setDeleteSourceFiles(true);
handler.setOutputChannel(output);
handler.setChmod(0400);
Message<?> message = MessageBuilder.withPayload(sourceFile).build();
handler.handleMessage(message);
Message<?> result = output.receive(0);
assertFileContentIsMatching(result);
File resultFile = messageToFile(result);
Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(resultFile.toPath());
assertThat(posixFilePermissions).containsOnly(PosixFilePermission.OWNER_READ);
assertThat(sourceFile.exists()).isFalse();
}

@Test
public void deleteSourceFileWithStringPayloadAndFileInstanceHeader() throws Exception {
QueueChannel output = new QueueChannel();
Expand Down

0 comments on commit bd2cf77

Please sign in to comment.