@@ -310,7 +310,7 @@ public function getAllInfo($reload=false,$com=true,$communityApplications=false)
310310 if (isset ($ ct ['Icon ' ])) $ tmp ['icon ' ] = $ ct ['Icon ' ];
311311 if (isset ($ ct ['Shell ' ])) $ tmp ['shell ' ] = $ ct ['Shell ' ];
312312 if (!$ communityApplications ) {
313- if (!is_file ($ tmp ['icon ' ]) || $ reload ) $ tmp ['icon ' ] = $ this ->getIcon ($ image ,$ name ,$ tmp [ ' icon ' ]);
313+ if (!is_file ($ tmp ['icon ' ]) || $ reload ) $ tmp ['icon ' ] = $ this ->getIcon ($ image ,$ name ,$ ct [ ' Icon ' ]);
314314 }
315315 if ($ ct ['Running ' ]) {
316316 $ port = &$ ct ['Ports ' ][0 ];
@@ -344,15 +344,17 @@ public function getAllInfo($reload=false,$com=true,$communityApplications=false)
344344 return $ info ;
345345 }
346346
347- public function getIcon ($ Repository ,$ contName ,$ tmpIconUrl ='' ) {
347+ public function getIcon ($ Repository ,$ contName ,$ iconUrl ='' ) {
348348 global $ docroot , $ dockerManPaths ;
349- $ imgUrl = $ this ->getTemplateValue ($ Repository , 'Icon ' ,'all ' ,$ contName );
350- if (!$ imgUrl ) $ imgUrl = $ tmpIconUrl ;
349+ $ imgUrl = $ iconUrl ?: $ this ->getTemplateValue ($ Repository , 'Icon ' ,'all ' ,$ contName );
351350 if (!$ imgUrl || trim ($ imgUrl ) == "/plugins/dynamix.docker.manager/images/question.png " ) return '' ;
352351
353- $ iconRAM = sprintf ( ' %s/%s-%s.png ' , $ dockerManPaths [ ' images-ram ' ], $ contName , ' icon ' );
354- $ icon = sprintf ('%s/%s -%s.png ' , $ dockerManPaths [ ' images ' ] , $ contName , ' icon ' );
352+ $ imgUrlHash = sha1 ( $ imgUrl );
353+ $ iconFile = sprintf ('%s-%s.png ' , ' icon ' , $ imgUrlHash );
355354
355+ $ iconRAM = sprintf ('%s/%s-%s ' , $ dockerManPaths ['images-ram ' ], $ contName , $ iconFile );
356+ $ icon = sprintf ('%s/%s ' , $ dockerManPaths ['images ' ], $ iconFile );
357+
356358 if (!is_dir (dirname ($ iconRAM ))) mkdir (dirname ($ iconRAM ), 0755 , true );
357359 if (!is_dir (dirname ($ icon ))) mkdir (dirname ($ icon ), 0755 , true );
358360
@@ -361,14 +363,47 @@ public function getIcon($Repository,$contName,$tmpIconUrl='') {
361363 @copy ($ icon , $ iconRAM );
362364 }
363365 if (!is_file ($ icon ) && is_file ($ iconRAM )) {
364- @copy ($ iconRAM ,$ icon );
366+ @copy ($ iconRAM , $ icon );
365367 }
366368 if (!is_file ($ iconRAM )) {
367369 exec ("logger -t webGUI -- \"$ contName: Could not download icon $ imgUrl \"" );
368370 }
371+ else {
372+ $ this ->purgeUnusedIconFiles ($ contName , $ iconFile );
373+ }
369374
370375 return (is_file ($ iconRAM )) ? str_replace ($ docroot , '' , $ iconRAM ) : '' ;
371376 }
377+
378+ public function purgeUnusedIconFiles ($ contName , $ keepIcon ='' ) {
379+ global $ docroot , $ dockerManPaths ;
380+
381+ $ icon_glob = sprintf ('%s/%s-*.png ' , $ dockerManPaths ['images-ram ' ], $ contName );
382+ $ ramFiles = glob ($ icon_glob );
383+ foreach ($ ramFiles as $ filename ) {
384+ if ( ($ keepIcon === '' ) || !(strpos ($ filename , $ keepIcon ) !== false ) ) {
385+ @unlink ($ filename );
386+ }
387+ }
388+
389+ $ icon_glob = sprintf ('%s/%s*.png ' , $ dockerManPaths ['images ' ], $ contName );
390+ foreach (glob ($ icon_glob ) as $ filename ) {
391+ if ( ($ keepIcon === '' ) || !(strpos ($ filename , $ keepIcon ) !== false ) ) {
392+ @unlink ($ filename );
393+ }
394+ }
395+
396+ $ icon_glob = sprintf ('%s/%s*.png ' , $ dockerManPaths ['images ' ], $ contName );
397+ foreach ($ ramFiles as $ ramFile ) {
398+ if ( strpos ($ ramFile , '-icon- ' ) !== false ) {
399+ $ suffix = end (explode ('- ' , $ ramFile ));
400+ if ( !glob ($ dockerManPaths ['images-ram ' ].'/*icon- ' .$ suffix ) ) {
401+ $ filename = sprintf ('%s/icon-%s ' , $ dockerManPaths ['images ' ], $ suffix );
402+ @unlink ($ filename );
403+ }
404+ }
405+ }
406+ }
372407}
373408
374409####################################
0 commit comments