Bug 61138 - DefaultTempFileCreationStrategy crashed in multi user mode
Summary: DefaultTempFileCreationStrategy crashed in multi user mode
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.16-FINAL
Hardware: PC Linux
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-31 07:38 UTC by Charles FENDT
Modified: 2017-05-31 08:19 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Charles FENDT 2017-05-31 07:38:21 UTC
The DefaultTempFileCreationStrategy creates a sub directory in the TEMP directory of the system

line 79: dir = new File(tmpDir, POIFILES);

But, in multi user mode, the directory /tmp/poifiles is not writeable because owned by another user

I changed this with 
dir = new File(tmpDir, IzarTempFileCreationStrategy.POIFILES + '-' + System.getProperty("user.name"));

And then i works fine !
Comment 1 Charles FENDT 2017-05-31 07:39:50 UTC
Line 128, i found a FIXME :
        // FIXME: Java 7+: use java.nio.Files#createTempDirectory
        final long n = random.nextLong();
        File newDirectory = new File(dir, prefix + Long.toString(n));

I change this with :
        final File newDirectory = Files.createTempDirectory(this.dir.toPath(), prefix).toFile();

:-)
Comment 2 Javen O'Neal 2017-05-31 08:15:43 UTC
(In reply to Charles FENDT from comment #0)
> The DefaultTempFileCreationStrategy creates a sub directory in the TEMP
> directory of the system
Check out o.a.p.util.TempFile#setTempFileCreationStrategy method so that you can plug in your own temporary file creation strategy to meet your needs by implementing your own TempFileCreationStrategy class, as you've done here (hopefully not modifying the DefaultTempFileCreationStrategy class, unless you want to maintain a private fork).
There have been a few other bugs and requests on the dev mailing list for providing more strategies, such as process-specific or thread-specific directories, fixed-size/auto-pruning directories, and directories cleaned up on a timer or from an explicit call rather than at JVM exit (for long-running JVM server processes), encrypted temp files, a common folder shared among multiple processes, with each process deleting its temp files at exit, and the last process deleting the temp directory.

I think the documentation mentions this, but maybe not prominently enough.
DefaultTempFileCreationStrategy.java:
> * See {@link TempFileCreationStrategy} for better strategies for long-running
> * processes or limited temporary storage.
And a few strategies talked about, but not implemented, in the TempFileCreationStrategy interface: [1]
At this point the strategies are too specific to a user's needs and the interface is small enough to easily implement that we haven't felt the need to add these to the POI API yet. If you want to develop some other TempFileCreationStrategies that you think would be universally usable (platform-independent), simple to use, and simple for us to maintain, and agnostic of filesystems and internationalization, then feel free to contribute a patch or pull request with unit tests. Ask if you need help.

In your example below, the user.name property may not exist, may contain characters that are not allowed in a file path (backslash and colon come to mind, though many other symbols and unicode could break on some file systems).

(In reply to Charles FENDT from comment #1)
> Line 128, i found a FIXME :
>         // FIXME: Java 7+: use java.nio.Files#createTempDirectory
Thanks. Apache POI still officially supports Java 6 in source and binary, so this FIXME stays in until we officially drop support for Java 6. We should probably have a decorator or a consistent comment string that could be searched on to find all the code that could be written more concisely in Java 7. I'm sure this isn't the only Java 7 fixme.

Ask around on the dev mailing list [2] or IRC channel [3] if you want to get involved with POI.

[1] https://poi.apache.org/apidocs/org/apache/poi/util/TempFileCreationStrategy.html
[2] http://poi.apache.org/mailinglists.html#The+POI+Developer+List
[3] https://poi.apache.org/mailinglists.html#IRC
Comment 3 Javen O'Neal 2017-05-31 08:19:36 UTC
Resolving as WONTFIX.

Users should implement their own TempFileCreationStrategy class and call TempFile.setTempFileCreationStrategy when they need something a strategy other than the default.

If you have any suggestions for updating the javadocs to make this clearer, I'll happily merge those changes.