MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / tar_check

Function tar_check

setup.py:297–326  ·  view source on GitHub ↗

Checks items in tar file have same , or if not None. We fail if items in tar file have different top-level directory names. path: The tar file. mode: As tarfile.open(). prefix: If not None, we fail if tar file's i

(path, mode='r:gz', prefix=None, remove=False)

Source from the content-addressed store, hash-verified

295
296
297def tar_check(path, mode='r:gz', prefix=None, remove=False):
298 '''
299 Checks items in tar file have same <top-directory>, or <prefix> if not None.
300
301 We fail if items in tar file have different top-level directory names.
302
303 path:
304 The tar file.
305 mode:
306 As tarfile.open().
307 prefix:
308 If not None, we fail if tar file&#x27;s <top-directory> is not <prefix>.
309
310 Returns the directory name (which will be <prefix> if not None).
311 ''&#x27;
312 with tarfile.open( path, mode) as t:
313 items = t.getnames()
314 assert items
315 item = items[0]
316 assert not item.startswith('./') and not item.startswith('../')
317 s = item.find('/')
318 if s == -1:
319 prefix_actual = item + '/'
320 else:
321 prefix_actual = item[:s+1]
322 if prefix:
323 assert prefix == prefix_actual, f'{path=} {prefix=} {prefix_actual=}'
324 for item in items[1:]:
325 assert item.startswith( prefix_actual), f'prefix_actual={prefix_actual!r} != item={item!r}'
326 return prefix_actual
327
328
329def tar_extract(path, mode='r:gz', prefix=None, exists='raise'):

Callers 2

tar_extractFunction · 0.85
get_mupdf_internalFunction · 0.85

Calls 1

findMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…