MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / CheckFilesystemForFS

Function CheckFilesystemForFS

Scripts/CI_FetchRootFS.py:92–160  ·  view source on GitHub ↗
(RootFSMountPath, RootFSPath, DistroFit)

Source from the content-addressed store, hash-verified

90 os.makedirs(RootFSPath)
91
92def CheckFilesystemForFS(RootFSMountPath, RootFSPath, DistroFit):
93 # Check if rootfs mount path exists
94 if (not os.path.exists(RootFSMountPath) or
95 not os.path.isdir(RootFSMountPath)):
96 print("RootFS mount path is wrong")
97 return False
98
99 # Check if rootfs path exists
100 if (not os.path.exists(RootFSPath) or
101 not os.path.isdir(RootFSPath)):
102 # Create this directory
103 os.makedirs(RootFSPath)
104
105 # Check if rootfs path exists
106 if not os.path.isdir(RootFSPath):
107 print("RootFS path is not a directory")
108 return False
109
110 # Check rootfs folder for image, copy and extract as necessary
111 MountRootFSImagePath = RootFSMountPath + DistroFit[3]
112 RootFSImagePath = RootFSPath + "/" + os.path.basename(DistroFit[3])
113 NeedsExtraction = False
114 PreviouslyExistingRootFS = False
115
116 if not os.path.exists(MountRootFSImagePath):
117 print("Image {} doesn't exist".format(MountRootFSImagePath))
118 return False
119
120 if not os.path.exists(RootFSImagePath):
121 # Copy over
122 print("RootFS image doesn't exist. Copying")
123 RemoveRootFSFolder(RootFSPath)
124 shutil.copyfile(MountRootFSImagePath, RootFSImagePath)
125 NeedsExtraction = True
126
127 # Check if the image needs to be extracted
128 if not os.path.exists(RootFSPath + "/usr"):
129 NeedsExtraction = True
130 else:
131 PreviouslyExistingRootFS = True
132
133 # Now hash the image
134 RootFSHash = HashFile(RootFSImagePath)
135 if RootFSHash != DistroFit[4]:
136 print("Hash {} did not match {}, copying new image".format(hex(RootFSHash), hex(DistroFit[4])))
137
138 if PreviouslyExistingRootFS:
139 RemoveRootFSFolder(RootFSPath)
140
141 shutil.copyfile(MountRootFSImagePath, RootFSImagePath)
142 NeedsExtraction = True
143
144 if NeedsExtraction:
145 print("Extracting rootfs")
146
147 CmdResult = subprocess.call(["unsquashfs", "-f", "-d", RootFSPath, RootFSImagePath])
148 if CmdResult != 0:
149 print("Couldn't extract squashfs. Removing image file to be safe")

Callers 1

mainFunction · 0.85

Calls 4

printFunction · 0.85
RemoveRootFSFolderFunction · 0.85
HashFileFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected