MCPcopy Create free account
hub / github.com/s3tools/s3cmd / InvalidateObjects

Method InvalidateObjects

S3/CloudFront.py:463–507  ·  view source on GitHub ↗
(self, uri, paths, default_index_file, invalidate_default_index_on_cf, invalidate_default_index_root_on_cf)

Source from the content-addressed store, hash-verified

461 return response
462
463 def InvalidateObjects(self, uri, paths, default_index_file, invalidate_default_index_on_cf, invalidate_default_index_root_on_cf):
464 # joseprio: if the user doesn't want to invalidate the default index
465 # path, or if the user wants to invalidate the root of the default
466 # index, we need to process those paths
467 if default_index_file is not None and (not invalidate_default_index_on_cf or invalidate_default_index_root_on_cf):
468 new_paths = []
469 default_index_suffix = '/' + default_index_file
470 for path in paths:
471 if path.endswith(default_index_suffix) or path == default_index_file:
472 if invalidate_default_index_on_cf:
473 new_paths.append(path)
474 if invalidate_default_index_root_on_cf:
475 new_paths.append(path[:-len(default_index_file)])
476 else:
477 new_paths.append(path)
478 paths = new_paths
479
480 # uri could be either cf:// or s3:// uri
481 cfuris = self.get_dist_name_for_bucket(uri)
482 if len(paths) > 999:
483 try:
484 tmp_filename = Utils.mktmpfile()
485 with open(deunicodise(tmp_filename), "w") as fp:
486 fp.write(deunicodise("\n".join(paths)+"\n"))
487 warning("Request to invalidate %d paths (max 999 supported)" % len(paths))
488 warning("All the paths are now saved in: %s" % tmp_filename)
489 except Exception:
490 pass
491 raise ParameterError("Too many paths to invalidate")
492
493 responses = []
494 for cfuri in cfuris:
495 invalbatch = InvalidationBatch(distribution = cfuri.dist_id(), paths = paths)
496 debug("InvalidateObjects(): request_body: %s" % invalbatch)
497 response = self.send_request("Invalidate", dist_id = cfuri.dist_id(),
498 body = str(invalbatch))
499 response['dist_id'] = cfuri.dist_id()
500 if response['status'] == 201:
501 inval_info = Invalidation(response['data']).info
502 response['request_id'] = inval_info['Id']
503 debug("InvalidateObjects(): response: %s" % response)
504
505 responses.append(response)
506
507 return responses
508
509 def GetInvalList(self, cfuri):
510 if cfuri.type != "cf":

Callers 1

invalidateMethod · 0.95

Calls 7

send_requestMethod · 0.95
ParameterErrorClass · 0.85
InvalidationBatchClass · 0.85
InvalidationClass · 0.85
dist_idMethod · 0.80
deunicodiseFunction · 0.70

Tested by

no test coverage detected