38
38
import org .yaml .snakeyaml .nodes .Tag ;
39
39
import org .yaml .snakeyaml .representer .Representer ;
40
40
import reactor .core .publisher .Mono ;
41
+ import reactor .core .scheduler .Schedulers ;
41
42
42
43
@ Slf4j
43
44
@ RequiredArgsConstructor
@@ -125,26 +126,30 @@ public Mono<Path> uploadConfigRelatedFile(FilePart file) {
125
126
String targetDirStr = ctx .getEnvironment ()
126
127
.getProperty (CONFIG_RELATED_UPLOADS_DIR_PROPERTY , CONFIG_RELATED_UPLOADS_DIR_DEFAULT );
127
128
128
- Path targetDir = Path .of (targetDirStr );
129
- if (!Files .exists (targetDir )) {
130
- try {
131
- Files .createDirectories (targetDir );
132
- } catch (IOException e ) {
133
- return Mono .error (
134
- new FileUploadException ("Error creating directory for uploads %s" .formatted (targetDir ), e ));
129
+ Mono <Path > directoryCreationMono = Mono .fromCallable (() -> {
130
+ Path targetDir = Path .of (targetDirStr );
131
+ if (!Files .exists (targetDir )) {
132
+ try {
133
+ Files .createDirectories (targetDir );
134
+ } catch (IOException e ) {
135
+ throw new FileUploadException ("Error creating directory for uploads %s" .formatted (targetDir ), e );
136
+ }
137
+ }
138
+ return targetDir ;
139
+ }).subscribeOn (Schedulers .boundedElastic ());
140
+
141
+ return directoryCreationMono .flatMap (dir -> {
142
+ Path targetFilePath = dir .resolve (file .filename () + "-" + Instant .now ().getEpochSecond ());
143
+ log .info ("Uploading config-related file {}" , targetFilePath );
144
+ if (Files .exists (targetFilePath )) {
145
+ log .info ("File {} already exists, it will be overwritten" , targetFilePath );
135
146
}
136
- }
137
-
138
- Path targetFilePath = targetDir .resolve (file .filename () + "-" + Instant .now ().getEpochSecond ());
139
- log .info ("Uploading config-related file {}" , targetFilePath );
140
- if (Files .exists (targetFilePath )) {
141
- log .info ("File {} already exists, it will be overwritten" , targetFilePath );
142
- }
143
147
144
- return file .transferTo (targetFilePath )
145
- .thenReturn (targetFilePath )
146
- .doOnError (th -> log .error ("Error uploading file {}" , targetFilePath , th ))
147
- .onErrorMap (th -> new FileUploadException (targetFilePath , th ));
148
+ return file .transferTo (targetFilePath )
149
+ .thenReturn (targetFilePath )
150
+ .doOnError (th -> log .error ("Error uploading file {}" , targetFilePath , th ))
151
+ .onErrorMap (th -> new FileUploadException (targetFilePath , th ));
152
+ });
148
153
}
149
154
150
155
private void checkIfDynamicConfigEnabled () {
@@ -163,8 +168,8 @@ private void writeYamlToFile(String yaml, Path path) {
163
168
if (!Files .exists (path .getParent ())) {
164
169
Files .createDirectories (path .getParent ());
165
170
}
166
- if (Files .exists (path ) && !Files .isWritable (path )) {
167
- throw new ValidationException ("File already exists and is not writable" );
171
+ if (Files .exists (path ) && ( !Files .isReadable ( path ) || ! Files . isWritable (path ) )) {
172
+ throw new ValidationException ("File already exists and is not readable or writable" );
168
173
}
169
174
try {
170
175
Files .writeString (
0 commit comments