You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces a separate cache directory for the ODR core library's temporary files. This is a good architectural improvement that better isolates cache data from output data.
Code Quality and Best Practices ✅
Positive aspects:
Clean separation of concerns between output and cache directories
Consistent naming convention (core_output and core_cache)
Proper cache cleanup with filesystem operations
Addition of std::error_code for error handling
Suggestions:
Error handling in C++: While you've added std::error_code ec in CoreWrapper.cpp, it's only used with std::filesystem::remove_all() but the error code is never checked. Consider logging failures:
std::filesystem::remove_all(cachePathCpp, ec);
if (ec) {
__android_log_print(ANDROID_LOG_WARN, "smn", "Failed to remove cache directory: %s", ec.message().c_str());
}
Potential Bugs or Issues ⚠️
Directory creation without error checking: In CoreWrapper.cpp, std::filesystem::create_directories(cachePathCpp) is called without error handling. If directory creation fails, the subsequent operations may fail unexpectedly.
Missing null/empty path validation: The cachePath parameter is extracted from Java but never validated before use. Consider adding validation:
if (cachePathCpp.empty()) {
env->SetIntField(result, errorField, -3);
return result;
}
Performance Considerations 🚀
Cache directory lifecycle: The current implementation removes and recreates the cache directory for each operation. This is safe but may have performance implications for frequent operations. Consider if the cache could be reused across operations when appropriate.
Filesystem operations: Multiple filesystem operations (remove_all, create_directories) are performed synchronously. For large cache directories, this could block the calling thread.
Security Concerns 🔒
Path traversal: While the cache path comes from controlled sources in this code, ensure that user-controlled paths cannot be injected elsewhere in the application that might lead to path traversal vulnerabilities.
Temporary file permissions: The code creates temporary directories but doesn't explicitly set permissions. On Android this is generally handled by the app sandbox, but it's worth noting.
Test Coverage 📋
Current coverage:
✅ Basic test updated to use the new cache path
✅ Test verifies successful parsing with cache directory
Missing coverage:
❌ No test for cache directory creation failure
❌ No test for concurrent access to cache directory
❌ No verification that cache is actually cleaned up after operations
Suggested test additions:
@TestpublicvoidtestCacheDirectoryCleanup() {
// Test that cache directory is removed after operationFilecacheDir = newFile(context.getCacheDir(), "core_cache");
assertFalse(cacheDir.exists() || cacheDir.list().length == 0);
}
@TestpublicvoidtestInvalidCachePath() {
// Test handling of invalid cache paths
}
Additional Notes
The removal of lastCoreOptions from RawLoader.java is a good cleanup since it wasn't being used
The changes are backward compatible as they only add a new field to CoreOptions
Consider documenting the purpose and lifecycle of the cache directory in code comments
Recommendation
Approve with suggestions - The core functionality is sound and improves the architecture. The suggested improvements around error handling and test coverage should be addressed in a follow-up PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.