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

validateOfficeTemplateProfileDirectory seems to check wrong thing #76

Closed
janssen opened this issue May 9, 2018 · 10 comments
Closed

validateOfficeTemplateProfileDirectory seems to check wrong thing #76

janssen opened this issue May 9, 2018 · 10 comments
Labels

Comments

@janssen
Copy link

janssen commented May 9, 2018

I'm trying to set a custom template directory, and failing. The code in validateOfficeTemplateProfileDirectory seems to require a subdirectory called "user". But clearly, as per https://wiki.documentfoundation.org/UserProfile#Default_locations, the directory ending with "user" is the user profile directory, it's not contained within the user profile directory. This function should be checking for the presence of "autocorr", "autotext", etc. as detailed under https://wiki.documentfoundation.org/UserProfile#User_profile_content.

// Template profile directory is not required.
if (templateProfileDir == null || new File(templateProfileDir, "user").isDirectory()) {
  return;
}
@sbraconnier
Copy link
Member

When LibreOffice starts for the first time, it will create a profile directory for the local user. Here on my Windows it's:

C:\Users\MyUser\AppData\Roaming\LibreOffice\4

and this directory must have a "user" directory in it, where is located all the stuff that has been saved for this specific profile.

When you set the templateProfileDir, JODConverter will copy the whole directory (including the user sub directory) in a temporary profile directory, and thus LibreOffice won't have to create the profile directory on startup.

@janssen
Copy link
Author

janssen commented May 9, 2018

OK, semantics. You think the directory that holds the "user" subdirectory is the profile directory, I think the "user" subdirectory is the profile directory (based on reading the text from https://wiki.documentfoundation.org/UserProfile). Confusing, probably should document this in LocalOfficeManager.Builder.templateProfileDir().

@janssen
Copy link
Author

janssen commented May 9, 2018

This is an actual problem. I'd like to get around the double startup of soffice.bin by pointing jodconverter to an existing profile directory. The user account running jodconverter might never have run soffice, so there would be no $HOME/.config/libreoffice/4/user. Ideally, I'd just use the pre-installed template version of the profile directory at /usr/lib/libreoffice/share/. But there's no extraneous "user" subdirectory there, so I can't. Fixing this misapprehension about what the profile directory is would fix that.

@sbraconnier
Copy link
Member

The Javadoc could be improved for sure. There is more on the wiki page about the templateProfileDir.

I understand your point about the share directory, but the fact is that this directory is way bigger than a regular profile directory. Don't forget that this "templateProfileDir" is COPIED into a temporary directory for the office instance that is about to be started (which is required in order to be able to start multiple office instances). Here on my Windows, pointing on the "share" directory will copy 150+ MB. A regular profile directory is around 1.5 MB. I don't think you will benefit from copying 150MB on each startup of soffice.bin instead of a double startup :).

The way I usually use the templateProfileDir is explained here. I create a copy of a profile directory elsewhere (outside the user account).

@janssen
Copy link
Author

janssen commented Jun 13, 2018

Hit this again. I'm running tests with jodconverter on a Gitlab CI setup which uses a Docker image with LibreOffice installed (the mbsi/s2i-java-libreoffice Docker from DockerHub). But my tests fail with this:

$ bash extract.sh -console -debug test1.doc
templatePath is /opt/app-root/src/.config/libreoffice/4/user
Temporary profile directory is /tmp/LibreOfficeUserTemplate2531831472878994228
java.io.FileNotFoundException: Source '/opt/app-root/src/.config/libreoffice/4/user' does not exist

Because LibreOffice has never been run on that virtual machine. We need some way of running this on a machine where LibreOffice has never been manually run. Or perhaps there's some way to run LibreOffice in a script which wouldn't do anything but would initialize that directory?

@janssen
Copy link
Author

janssen commented Jun 14, 2018

I understand your point about the share directory, but the fact is that this directory is way bigger than a regular profile directory. Don't forget that this "templateProfileDir" is COPIED into a temporary directory for the office instance that is about to be started (which is required in order to be able to start multiple office instances). Here on my Windows, pointing on the "share" directory will copy 150+ MB. A regular profile directory is around 1.5 MB. I don't think you will benefit from copying 150MB on each startup of soffice.bin instead of a double startup :).

But it would be OK for a fallback, wouldn't it? Use the user config if it exists; otherwise, copy the share directory. That would allow JODConverter to actually not fail in situations in which it currently fails.

@sbraconnier
Copy link
Member

I assume that your script extract.sh is aware of the '/opt/app-root/src/.config/libreoffice/4/user' directory ? Or if it is hard coded into the program being called ? If it's in the script, maybe you could check first if the directory exists, and if not, just don't set the templateProfileDir ?

@sbraconnier
Copy link
Member

But it would be OK for a fallback, wouldn't it? Use the user config if it exists; otherwise, copy the share directory. That would allow JODConverter to actually not fail in situations in which it currently fails.

This is an interesting idea, it would not be that hard to implement. Let me check this and come back to you.

@sbraconnier
Copy link
Member

Closing. See #81

@janssen
Copy link
Author

janssen commented Jun 15, 2018

I assume that your script extract.sh is aware of the '/opt/app-root/src/.config/libreoffice/4/user' directory ? Or if it is hard coded into the program being called ? If it's in the script, maybe you could check first if the directory exists, and if not, just don't set the templateProfileDir ?

Tried this; works OK, too. Still get the double startup, but only once.

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

No branches or pull requests

2 participants