@@ -137,7 +137,14 @@ public function handleDownload(Request $request, Response $response): ?bool {
137137 }
138138
139139 $ folder = $ node ->getNode ();
140- $ event = new BeforeZipCreatedEvent ($ folder , $ files );
140+ $ nodes = empty ($ files ) ? $ folder ->getDirectoryListing () : [];
141+ foreach ($ files as $ path ) {
142+ $ child = $ node ->getChild ($ path );
143+ assert ($ child instanceof Node);
144+ $ nodes [] = $ child ->getNode ();
145+ }
146+
147+ $ event = new BeforeZipCreatedEvent ($ folder , $ files , $ nodes );
141148 $ this ->eventDispatcher ->dispatchTyped ($ event );
142149 if ((!$ event ->isSuccessful ()) || $ event ->getErrorMessage () !== null ) {
143150 $ errorMessage = $ event ->getErrorMessage ();
@@ -150,12 +157,7 @@ public function handleDownload(Request $request, Response $response): ?bool {
150157 throw new Forbidden ($ errorMessage );
151158 }
152159
153- $ content = empty ($ files ) ? $ folder ->getDirectoryListing () : [];
154- foreach ($ files as $ path ) {
155- $ child = $ node ->getChild ($ path );
156- assert ($ child instanceof Node);
157- $ content [] = $ child ->getNode ();
158- }
160+ $ nodes = $ event ->getNodes ();
159161
160162 $ archiveName = $ folder ->getName ();
161163 if (count (explode ('/ ' , trim ($ folder ->getPath (), '/ ' ), 3 )) === 2 ) {
@@ -169,13 +171,13 @@ public function handleDownload(Request $request, Response $response): ?bool {
169171 $ rootPath = dirname ($ folder ->getPath ());
170172 }
171173
172- $ streamer = new Streamer ($ tarRequest , -1 , count ($ content ), $ this ->timezoneFactory );
174+ $ streamer = new Streamer ($ tarRequest , -1 , count ($ nodes ), $ this ->timezoneFactory );
173175 $ streamer ->sendHeaders ($ archiveName );
174176 // For full folder downloads we also add the folder itself to the archive
175177 if (empty ($ files )) {
176178 $ streamer ->addEmptyDir ($ archiveName );
177179 }
178- foreach ($ content as $ node ) {
180+ foreach ($ nodes as $ node ) {
179181 $ this ->streamNode ($ streamer , $ node , $ rootPath );
180182 }
181183 $ streamer ->finalize ();
0 commit comments