-
Notifications
You must be signed in to change notification settings - Fork 288
Crash at startup when local storage directory is not writable #1603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ad91f6
413e847
53b4f06
ffe8d98
d8e2f16
c6c4de1
8079058
6cf3d39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,16 @@ | |
| * ****************************************************************************** */ | ||
| package org.eclipse.openvsx.storage; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import jakarta.annotation.PostConstruct; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.eclipse.openvsx.entities.FileResource; | ||
| import org.eclipse.openvsx.entities.Namespace; | ||
|
|
@@ -22,14 +32,6 @@ | |
| import org.springframework.web.server.ServerErrorException; | ||
| import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.StandardCopyOption; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Component | ||
| public class LocalStorageService implements IStorageService { | ||
|
|
||
|
|
@@ -40,6 +42,27 @@ public class LocalStorageService implements IStorageService { | |
| public boolean isEnabled() { | ||
| return !StringUtils.isEmpty(storageDirectory); | ||
| } | ||
|
|
||
| @PostConstruct | ||
| public void validateStorageDirectory() throws IOException { | ||
| if (!isEnabled()) { | ||
| return; | ||
| } | ||
|
|
||
| var storageDirectoryPath = Path.of(storageDirectory).toAbsolutePath(); | ||
|
|
||
| if (!Files.exists(storageDirectoryPath)) { | ||
| Files.createDirectories(storageDirectoryPath); | ||
| } | ||
|
|
||
| if (!Files.isDirectory(storageDirectoryPath)) { | ||
| throw new IllegalStateException("Local storage directory '" + storageDirectory + "' is not a directory"); | ||
| } | ||
|
|
||
| if (!Files.isWritable(storageDirectoryPath)) { | ||
| throw new IllegalStateException("Local storage directory '" + storageDirectory + "' is not writable"); | ||
| } | ||
| } | ||
|
Comment on lines
46
to
65
|
||
|
|
||
| @Override | ||
| public void uploadFile(TempFile tempFile) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s no blank line between the package declaration and the first import. Other classes in this package keep a blank line after
package ...;(e.g.,AwsStorageService.java:11-13), and this can trip formatting/checkstyle rules.