@@ -625,7 +625,7 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws Se
625
625
}
626
626
627
627
InputStream resourceInputStream = null ;
628
-
628
+ File tempContentFile = null ;
629
629
try {
630
630
// Append data specified in ranges to existing content for this
631
631
// resource - create a temp. file on the local filesystem to
@@ -634,8 +634,8 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws Se
634
634
if (range == IGNORE ) {
635
635
resourceInputStream = req .getInputStream ();
636
636
} else {
637
- File contentFile = executePartialPut (req , range , path );
638
- resourceInputStream = new FileInputStream (contentFile );
637
+ tempContentFile = executePartialPut (req , range , path );
638
+ resourceInputStream = new FileInputStream (tempContentFile );
639
639
}
640
640
641
641
if (resources .write (path , resourceInputStream , true )) {
@@ -659,6 +659,9 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws Se
659
659
// Ignore
660
660
}
661
661
}
662
+ if (tempContentFile != null ) {
663
+ tempContentFile .delete ();
664
+ }
662
665
}
663
666
}
664
667
@@ -681,13 +684,7 @@ protected File executePartialPut(HttpServletRequest req, Range range, String pat
681
684
// resource - create a temp. file on the local filesystem to
682
685
// perform this operation
683
686
File tempDir = (File ) getServletContext ().getAttribute (ServletContext .TEMPDIR );
684
- // Convert all '/' characters to '.' in resourcePath
685
- String convertedResourcePath = path .replace ('/' , '.' );
686
- File contentFile = new File (tempDir , convertedResourcePath );
687
- if (contentFile .createNewFile ()) {
688
- // Clean up contentFile when Tomcat is terminated
689
- contentFile .deleteOnExit ();
690
- }
687
+ File contentFile = File .createTempFile ("put-part-" , null , tempDir );
691
688
692
689
try (RandomAccessFile randAccessContentFile = new RandomAccessFile (contentFile , "rw" )) {
693
690
0 commit comments