30
30
31
31
32
32
from ..config import Config
33
- from ..utils import parse_version
33
+ from ..utils import parse_version , md5sum
34
34
from ..utils .images import default_images_directory
35
35
36
36
from .project import Project
@@ -308,12 +308,21 @@ async def load_projects(self):
308
308
except OSError as e :
309
309
log .error (str (e ))
310
310
311
+
311
312
@staticmethod
312
- def install_resource_files (dst_path , resource_name ):
313
+ def install_resource_files (dst_path , resource_name , upgrade_resources = True ):
313
314
"""
314
315
Install files from resources to user's file system
315
316
"""
316
317
318
+ def should_copy (src , dst , upgrade_resources ):
319
+ if not os .path .exists (dst ):
320
+ return True
321
+ if upgrade_resources is False :
322
+ return False
323
+ # copy the resource if it is different
324
+ return md5sum (src ) != md5sum (dst )
325
+
317
326
if hasattr (sys , "frozen" ) and sys .platform .startswith ("win" ):
318
327
resource_path = os .path .normpath (os .path .join (os .path .dirname (sys .executable ), resource_name ))
319
328
for filename in os .listdir (resource_path ):
@@ -322,7 +331,7 @@ def install_resource_files(dst_path, resource_name):
322
331
else :
323
332
for entry in importlib_resources .files ('gns3server' ).joinpath (resource_name ).iterdir ():
324
333
full_path = os .path .join (dst_path , entry .name )
325
- if entry .is_file () and not os . path . exists ( full_path ):
334
+ if entry .is_file () and should_copy ( str ( entry ), full_path , upgrade_resources ):
326
335
log .debug (f'Installing { resource_name } resource file "{ entry .name } " to "{ full_path } "' )
327
336
shutil .copy (str (entry ), os .path .join (dst_path , entry .name ))
328
337
elif entry .is_dir ():
@@ -338,7 +347,7 @@ def _install_base_configs(self):
338
347
dst_path = self .configs_path ()
339
348
log .info (f"Installing base configs in '{ dst_path } '" )
340
349
try :
341
- Controller .install_resource_files (dst_path , "configs" )
350
+ Controller .install_resource_files (dst_path , "configs" , upgrade_resources = False )
342
351
except OSError as e :
343
352
log .error (f"Could not install base config files to { dst_path } : { e } " )
344
353
@@ -351,7 +360,7 @@ def _install_builtin_disks(self):
351
360
dst_path = self .disks_path ()
352
361
log .info (f"Installing built-in disks in '{ dst_path } '" )
353
362
try :
354
- Controller .install_resource_files (dst_path , "disks" )
363
+ Controller .install_resource_files (dst_path , "disks" , upgrade_resources = False )
355
364
except OSError as e :
356
365
log .error (f"Could not install disk files to { dst_path } : { e } " )
357
366
0 commit comments