MCPcopy Create free account
hub / github.com/LOLINTERNETZ/vscodeoffline / download_update

Method download_update

vscoffline/sync.py:101–138  ·  view source on GitHub ↗
(self, destination)

Source from the content-addressed store, hash-verified

99 return False
100
101 def download_update(self, destination):
102 if not self.checkedForUpdate:
103 log.warning(
104 'Cannot download update if the update definition has not been downloaded')
105 return
106 if not self.updateurl:
107 log.warning(
108 'Cannot download update if there is no url to download from')
109 return
110
111 destination = os.path.join(destination, self.identity, self.quality)
112 if not os.path.isdir(destination):
113 os.makedirs(destination)
114 suffix = pathlib.Path(self.updateurl).suffix
115 if '.gz' in suffix:
116 suffix = ''.join(pathlib.Path(self.updateurl).suffixes)
117 destfile = os.path.join(destination, f'vscode-{self.name}{suffix}')
118
119 if os.path.exists(destfile) and vsc.Utility.hash_file_and_check(destfile, self.sha256hash):
120 log.debug(f'Previously downloaded {self}')
121 else:
122 # Some old releases (e.g. stable/win32 - Version: 1.83.1) still reference the old CDN and fail the download,
123 # so these are skipped.
124 if self.updateurl.startswith("https://az764295.vo.msecnd.net"):
125 log.info(f"Skipping old version, no longer available {self}")
126 return False
127 log.info(f'Downloading {self} to {destfile}')
128 result = requests.get(
129 self.updateurl, allow_redirects=True, timeout=vsc.TIMEOUT)
130 open(destfile, 'wb').write(result.content)
131
132 if not vsc.Utility.hash_file_and_check(destfile, self.sha256hash):
133 log.warning(
134 f'HASH MISMATCH for {self} at {destfile} expected {self.sha256hash}. Removing local file.')
135 os.remove(destfile)
136 return False
137 log.debug(f'Hash ok for {self} with {self.sha256hash}')
138 return True
139
140 def save_state(self, destination):
141 destination = os.path.join(destination, self.identity)

Callers 1

sync.pyFile · 0.80

Calls 1

hash_file_and_checkMethod · 0.80

Tested by

no test coverage detected