@@ -303,7 +303,7 @@ public function getAllInfo($reload=false,$com=true,$communityApplications=false)
303303 if ($ ct ['Url ' ] && !$ tmp ['url ' ]) $ tmp ['url ' ] = $ ct ['Url ' ];
304304 if ($ ct ['Icon ' ]) $ tmp ['icon ' ] = $ ct ['Icon ' ];
305305 if ( ! $ communityApplications ) {
306- if (!is_file ($ tmp ['icon ' ]) || $ reload ) $ tmp ['icon ' ] = $ this ->getIcon ($ image ,$ name ,$ tmp [ ' icon ' ]);
306+ if (!is_file ($ tmp ['icon ' ]) || $ reload ) $ tmp ['icon ' ] = $ this ->getIcon ($ image ,$ name ,$ ct [ ' Icon ' ]);
307307 }
308308 if ($ ct ['Running ' ]) {
309309 $ port = &$ ct ['Ports ' ][0 ];
@@ -336,15 +336,16 @@ public function getAllInfo($reload=false,$com=true,$communityApplications=false)
336336 return $ info ;
337337 }
338338
339- public function getIcon ($ Repository ,$ contName ,$ tmpIconUrl ='' ) {
339+ public function getIcon ($ Repository ,$ contName ,$ iconUrl ='' ) {
340340 global $ docroot , $ dockerManPaths ;
341- $ imgUrl = $ this ->getTemplateValue ($ Repository , 'Icon ' ,'all ' ,$ contName );
342- if (!$ imgUrl ) $ imgUrl = $ tmpIconUrl ;
341+ $ imgUrl = $ iconUrl ?: $ this ->getTemplateValue ($ Repository , 'Icon ' ,'all ' ,$ contName );
343342 if (!$ imgUrl || trim ($ imgUrl ) == "/plugins/dynamix.docker.manager/images/question.png " ) return '' ;
344343
345- $ imageName = $ contName ?: $ name ;
346- $ iconRAM = sprintf ('%s/%s-%s.png ' , $ dockerManPaths ['images-ram ' ], $ contName , 'icon ' );
347- $ icon = sprintf ('%s/%s-%s.png ' , $ dockerManPaths ['images ' ], $ contName , 'icon ' );
344+ $ imgUrlHash = sha1 ($ imgUrl );
345+ $ iconFile = sprintf ('%s-%s.png ' , 'icon ' , $ imgUrlHash );
346+
347+ $ iconRAM = sprintf ('%s/%s-%s ' , $ dockerManPaths ['images-ram ' ], $ contName , $ iconFile );
348+ $ icon = sprintf ('%s/%s ' , $ dockerManPaths ['images ' ], $ iconFile );
348349
349350 if (!is_dir (dirname ($ iconRAM ))) mkdir (dirname ($ iconRAM ), 0755 , true );
350351 if (!is_dir (dirname ($ icon ))) mkdir (dirname ($ icon ), 0755 , true );
@@ -354,14 +355,47 @@ public function getIcon($Repository,$contName,$tmpIconUrl='') {
354355 @copy ($ icon , $ iconRAM );
355356 }
356357 if (!is_file ($ icon ) && is_file ($ iconRAM )) {
357- @copy ($ iconRAM ,$ icon );
358+ @copy ($ iconRAM , $ icon );
358359 }
359360 if ( !is_file ($ iconRAM ) ) {
360- exec ("/usr/bin/logger " .escapeshellarg ("$ imageName: Could not download icon $ imgUrl " ));
361+ exec ("/usr/bin/logger " .escapeshellarg ("$ contName: Could not download icon $ imgUrl " ));
362+ }
363+ else {
364+ $ this ->purgeUnusedIconFiles ($ contName , $ iconFile );
361365 }
362366
363367 return (is_file ($ iconRAM )) ? str_replace ($ docroot , '' , $ iconRAM ) : '' ;
364368 }
369+
370+ public function purgeUnusedIconFiles ($ contName , $ keepIcon ='' ) {
371+ global $ docroot , $ dockerManPaths ;
372+
373+ $ icon_glob = sprintf ('%s/%s-*.png ' , $ dockerManPaths ['images-ram ' ], $ contName );
374+ $ ramFiles = glob ($ icon_glob );
375+ foreach ($ ramFiles as $ filename ) {
376+ if ( ($ keepIcon === '' ) || !(strpos ($ filename , $ keepIcon ) !== false ) ) {
377+ @unlink ($ filename );
378+ }
379+ }
380+
381+ $ icon_glob = sprintf ('%s/%s*.png ' , $ dockerManPaths ['images ' ], $ contName );
382+ foreach (glob ($ icon_glob ) as $ filename ) {
383+ if ( ($ keepIcon === '' ) || !(strpos ($ filename , $ keepIcon ) !== false ) ) {
384+ @unlink ($ filename );
385+ }
386+ }
387+
388+ $ icon_glob = sprintf ('%s/%s*.png ' , $ dockerManPaths ['images ' ], $ contName );
389+ foreach ($ ramFiles as $ ramFile ) {
390+ if ( strpos ($ ramFile , '-icon- ' ) !== false ) {
391+ $ suffix = end (explode ('- ' , $ ramFile ));
392+ if ( !glob ($ dockerManPaths ['images-ram ' ].'/*icon- ' .$ suffix ) ) {
393+ $ filename = sprintf ('%s/icon-%s ' , $ dockerManPaths ['images ' ], $ suffix );
394+ @unlink ($ filename );
395+ }
396+ }
397+ }
398+ }
365399}
366400
367401####################################
0 commit comments