Skip to content
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

[JSPWIKI-1172] Set jspwiki.workDir default to servlet context temp directory #282

Merged
merged 1 commit into from Jul 29, 2023

Conversation

arturobernalg
Copy link
Member

@arturobernalg arturobernalg commented Jun 3, 2023

Description:

This pull request addresses the issue JSPWIKI-1172 by changing the default value of jspwiki.workDir from java.io.tmpdir to the servlet container's context-specific temp directory, as provided by the "javax.servlet.context.tempdir" context attribute.

Key Changes:

  • A new ServletContextListener, WikiServletContextListener, has been created to manage this setting during context initialization.
  • In case the servlet container does not provide a temporary directory, the system's default temporary directory is used as a fallback.
  • This modification aids in avoiding possible problems associated with space limitations in the system's temporary directory, especially on Unix systems where /tmp is often space-limited and sometimes located in a ramdisk.

Testing:

  • Unit tests have been added for the new WikiServletContextListener to ensure the directory is set correctly during context initialization, and that an exception is thrown if the directory is not writable.

Copy link
Contributor

@juanpablo-santos juanpablo-santos left a comment

Choose a reason for hiding this comment

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

changes requested

*
* @since 2.12.0
*/
public class WikiServletContextListener implements ServletContextListener {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @arturobernalg , thanks for looking into this!

Instead of adding a new servlet, I think it would be better to go through WikiBootstrapServletContextListener, which calls Wiki.init( servletContext), which in turn delegates to PropertyReader.loadWebAppProps( servletContext ) to load the wiki properties (from jspwiki[-custom].properties, system env & props, etc.). I'd check there for jspwiki.workDir existence. If it's set, then we do nothing. If it's missing, then we set it to javax.servlet.context.tempdir (or, if this doesn't exist, java.io.tmpdir) on the properties object.

Once the jspwiki.workDir is set on PropertyReader, then we can remove the java.io.tmpdir usage on WikiEngine, and refactor Installer to use the wiki properties instead of directly using java.io.tmpdir.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @juanpablo-santos

I've made the changes as per your suggestion. I modified WikiBootstrapServletContextListener to check and set 'jspwiki.workDir' and refactored Installer to use this property instead of 'java.io.tmpdir'. I also removed the direct usage of 'java.io.tmpdir' in WikiEngine. Please have a look at the latest commit.

Thanks for your valuable feedback!

Copy link
Contributor

@juanpablo-santos juanpablo-santos left a comment

Choose a reason for hiding this comment

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

a couple of small changes and this is ready to go!

* @param servletContext the Servlet context from which to fetch the tempdir if needed
* @since JSPWiki 2.11.1
*/
void setWorkDir(final Properties properties, final ServletContext servletContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi,

my bad, I was meaning do all of these changes inside PropertyReader, just before the variable expansion. That way all property reading/mungling is done inside PropertyReader#loadWebAppProps

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -86,6 +86,7 @@ public Installer( final HttpServletRequest request, final ServletConfig config )
// Stash the request
m_request = request;
m_validated = false;
TMP_DIR = m_engine.getWikiProperties().getProperty( "java.io.tmpdir" );
Copy link
Contributor

Choose a reason for hiding this comment

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

should be m_engine.getWikiProperties().getProperty( "jspwiki.workDir" )

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

This commit makes a few key changes:
1. PropertyReader now checks for the existence of jspwiki.workDir. If it's missing, the servlet context's temporary directory (or the system's temporary directory if that's unavailable) is set as the working directory.
2. Removed direct usage of java.io.tmpdir in WikiEngine since jspwiki.workDir is now ensured to be set in PropertyReader.
3. Refactored the Installer to use wiki properties (specifically, jspwiki.workDir) instead of directly using java.io.tmpdir.

These changes streamline the handling of the working directory and ensure that it's consistently sourced from the same place (the wiki properties).
Copy link
Contributor

@juanpablo-santos juanpablo-santos left a comment

Choose a reason for hiding this comment

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

lgtm

@juanpablo-santos juanpablo-santos merged commit f1cb2f6 into apache:master Jul 29, 2023
1 check passed
@juanpablo-santos
Copy link
Contributor

merged in 2.12.1-git-02, would you mind resolving the associated jira issue? thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants