From c24ea8311d9927de5ea084caa569ef5c3c9dc5c0 Mon Sep 17 00:00:00 2001 From: Manish Date: Fri, 1 May 2020 10:44:59 +1000 Subject: [PATCH] Hard link bundles if on same partition, else copy as before --- generator/main.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/generator/main.py b/generator/main.py index e45691d..8bf118d 100644 --- a/generator/main.py +++ b/generator/main.py @@ -38,11 +38,22 @@ class extractData: infoFiles.append(File) return infoFiles - def copyBundle(self, bundleSrc, activityName): - shutil.copy2( - bundleSrc, - self.websiteDir+"bundles/"+activityName+".xo" - ) + def copyBundle(self, source, activityName): + destination = self.websiteDir+"bundles/"+activityName+".xo" + # move this code block to a portable function + # copyFile(source, destination) + try: + # hard link if on same partition + os.link(source, destination) + except FileExistsError: + # FIXME: create a portable function to compare if two files + # are same and use it here + pass + except OSError: + # copy if on different partition + shutil.copy2(source, destination) + except Exception as unknownError: + raise unknownError def createDirectories(self): assert CreateDir(self.websiteDir+"app")