2727import org .eclipse .openvsx .search .SearchUtilService ;
2828import org .eclipse .openvsx .util .*;
2929import org .jobrunr .scheduling .JobRequestScheduler ;
30+ import org .slf4j .Logger ;
31+ import org .slf4j .LoggerFactory ;
3032import org .springframework .beans .factory .annotation .Value ;
3133import org .springframework .http .HttpStatus ;
3234import org .springframework .stereotype .Component ;
4749public class ExtensionService {
4850 private static final int MAX_CONTENT_SIZE = 512 * 1024 * 1024 ;
4951
52+ private final Logger logger = LoggerFactory .getLogger (ExtensionService .class );
53+
5054 private final EntityManager entityManager ;
5155 private final RepositoryService repositories ;
5256 private final SearchUtilService search ;
@@ -97,7 +101,19 @@ public ExtensionVersion publishVersion(InputStream content, PersonalAccessToken
97101 return publishVersionWithScan (content , token );
98102 } else {
99103 var extensionFile = createExtensionFile (content );
100- doPublish (extensionFile , null , token , TimeUtil .getCurrentUTC (), true );
104+ try {
105+ doPublish (extensionFile , null , token , TimeUtil .getCurrentUTC (), true );
106+ } catch (ErrorResultException exc ) {
107+ // In case publication fails early on we need to
108+ // delete the temporary extension file, otherwise
109+ // it's deleted within the publishAsync method.
110+ try {
111+ extensionFile .close ();
112+ } catch (IOException e ) {
113+ logger .error ("failed to delete temp file" , e );
114+ }
115+ throw exc ;
116+ }
101117 publishHandler .publishAsync (extensionFile , this );
102118 var download = extensionFile .getResource ();
103119 publishHandler .schedulePublicIdJob (download );
@@ -115,7 +131,7 @@ private ExtensionVersion publishVersionWithScan(InputStream content, PersonalAcc
115131 scanService .runValidation (scan , extensionFile , token .getUser ());
116132
117133 doPublish (extensionFile , null , token , TimeUtil .getCurrentUTC (), true );
118-
134+
119135 // Publish async handles requesting the longrunning scans
120136 publishHandler .publishAsync (extensionFile , this , scan );
121137 var download = extensionFile .getResource ();
@@ -126,6 +142,16 @@ private ExtensionVersion publishVersionWithScan(InputStream content, PersonalAcc
126142 if (scan != null && !scan .isCompleted ()) {
127143 scanService .removeScan (scan );
128144 }
145+
146+ // In case publication fails early on we need to
147+ // delete the temporary extension file, otherwise
148+ // it's deleted within the publishAsync method.
149+ try {
150+ extensionFile .close ();
151+ } catch (IOException ioe ) {
152+ logger .error ("failed to delete temp file" , ioe );
153+ }
154+
129155 throw e ;
130156 } catch (Exception e ) {
131157 if (scan != null && !scan .isCompleted ()) {
0 commit comments