Skip to content

Conversation

@Pranav-0440
Copy link
Contributor

When ovsx.storage.local.directory is configured but not writable,
the application starts successfully and later fails at runtime
with inconsistent behavior.

This change adds a startup validation to ensure the local storage
directory exists and is writable. If not, the application fails fast
with a clear error message.

This prevents corrupted state and improves operator feedback.
fixes - #1158

Signed-off-by: Pranav-0440 <pranavghorpade61@gmail.com>
Copilot AI review requested due to automatic review settings February 10, 2026 17:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds fail-fast startup validation for ovsx.storage.local.directory so the server errors early when local storage is configured but not writable, avoiding later inconsistent runtime behavior (Issue #1158).

Changes:

  • Add a @PostConstruct startup check that ensures the configured local storage directory exists and is writable.
  • Throw a clear startup exception when the directory cannot be created or written to.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 10 to 12
package org.eclipse.openvsx.storage;
import jakarta.annotation.PostConstruct;

Copy link

Copilot AI Feb 10, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines 57 to 60
// Verify directory is writable by creating a temp file
Path testFile = dir.resolve(".ovsx_write_test");
Files.writeString(testFile, "test");
Files.deleteIfExists(testFile);
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The writability check uses a fixed filename (.ovsx_write_test) and Files.writeString(...), which will overwrite an existing file and can also follow a pre-existing symlink. This can cause false negatives (directory is writable but the file isn’t) and introduces a symlink/clobber risk. Prefer creating a new temp file in the directory (e.g., Files.createTempFile(dir, ...) / CREATE_NEW) and ensure it’s cleaned up in a finally block.

Suggested change
// Verify directory is writable by creating a temp file
Path testFile = dir.resolve(".ovsx_write_test");
Files.writeString(testFile, "test");
Files.deleteIfExists(testFile);
// Verify directory is writable by creating and removing a temp file
Path testFile = null;
try {
testFile = Files.createTempFile(dir, ".ovsx_write_test", null);
Files.writeString(testFile, "test");
} finally {
if (testFile != null) {
Files.deleteIfExists(testFile);
}
}

Copilot uses AI. Check for mistakes.
Comment on lines 62 to 66
} catch (Exception e) {
throw new IllegalStateException(
"Local storage directory is not writable: " + storageDirectory +
". Please check permissions for 'ovsx.storage.local.directory'.",
e
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching Exception and always reporting "directory is not writable" can be misleading for cases like an invalid path (InvalidPathException) or other configuration errors. Consider catching the expected I/O/security exceptions for the permissions check, and include the resolved absolute path in the message to make operator diagnosis easier.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are ways to test the permissions on the local storage directory instead of trying to create a file in it which is the preferred way to do that.

Comment on lines 45 to 69
@PostConstruct
public void validateStorageDirectory() {
if (!isEnabled()) {
return;
}

try {
Path dir = Path.of(storageDirectory).toAbsolutePath();

// Ensure directory exists
Files.createDirectories(dir);

// Verify directory is writable by creating a temp file
Path testFile = dir.resolve(".ovsx_write_test");
Files.writeString(testFile, "test");
Files.deleteIfExists(testFile);

} catch (Exception e) {
throw new IllegalStateException(
"Local storage directory is not writable: " + storageDirectory +
". Please check permissions for 'ovsx.storage.local.directory'.",
e
);
}
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new startup behavior (fail-fast validation) but there are no focused tests exercising the writable vs non-writable cases for local storage. Given the existing test coverage for other storage services, it would be good to add tests that assert the app context fails to start (or the validator throws) when the directory is not writable, and succeeds when it is.

Copilot uses AI. Check for mistakes.
Comment on lines 62 to 66
} catch (Exception e) {
throw new IllegalStateException(
"Local storage directory is not writable: " + storageDirectory +
". Please check permissions for 'ovsx.storage.local.directory'.",
e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are ways to test the permissions on the local storage directory instead of trying to create a file in it which is the preferred way to do that.

Signed-off-by: Pranav-0440 <pranavghorpade61@gmail.com>
@Pranav-0440
Copy link
Contributor Author

Thanks @netomi for the feedback. That makes sense.
I've updated the implementation to check writability using Files.isWritable instead of creating a temporary file.

@netomi netomi merged commit e2470ec into eclipse:master Feb 11, 2026
4 checks passed
@Pranav-0440
Copy link
Contributor Author

Hi @netomi ,
I’ve really enjoyed contributing to this project and learning the architecture.
I’m very interested in applying for GSoC this year and was wondering if this project plans to participate.
If yes, I’d love to understand which areas need deeper work so I can prepare accordingly.
Thank you for your guidance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants