# TODO change to Content-Disposition filename https://tools.ietf.org/html/rfc6266
file_pkg = None
error_text = ""
+ fs_rollback = []
+
try:
if content_range_text:
content_range = (
else:
self.fs.file_delete(proposed_revision_path, ignore_non_exist=True)
self.fs.mkdir(proposed_revision_path)
+ fs_rollback.append(proposed_revision_path)
storage = self.fs.get_params()
- storage["folder"] = _id
+ storage["folder"] = proposed_revision_path
file_path = (proposed_revision_path, filename)
if self.fs.file_exists(file_path, "file"):
self.fs.file_delete(proposed_revision_path, ignore_non_exist=True)
raise e
- # Copy the revision to the active package name by its original id
- shutil.rmtree(self.fs.path + current_revision_path, ignore_errors=True)
- os.rename(self.fs.path + proposed_revision_path, self.fs.path + current_revision_path)
- self.fs.file_delete(current_revision_path, ignore_non_exist=True)
- self.fs.mkdir(current_revision_path)
- self.fs.reverse_sync(from_path=current_revision_path)
- shutil.rmtree(self.fs.path + _id)
-
- current_desc["_admin"]["storage"] = storage
- current_desc["_admin"]["onboardingState"] = "ONBOARDED"
- current_desc["_admin"]["operationalState"] = "ENABLED"
indata = self._remove_envelop(indata)
if kwargs:
self._update_input_with_kwargs(indata, kwargs)
+ current_desc["_admin"]["storage"] = storage
+ current_desc["_admin"]["onboardingState"] = "ONBOARDED"
+ current_desc["_admin"]["operationalState"] = "ENABLED"
+ current_desc["_admin"]["modified"] = time()
+ current_desc["_admin"]["revision"] = revision
+
deep_update_rfc7396(current_desc, indata)
current_desc = self.check_conflict_on_edit(
session, current_desc, indata, _id=_id
)
- current_desc["_admin"]["modified"] = time()
- current_desc["_admin"]["revision"] = revision
+
+ # Copy the revision to the active package name by its original id
+ shutil.rmtree(self.fs.path + current_revision_path, ignore_errors=True)
+ os.rename(self.fs.path + proposed_revision_path, self.fs.path + current_revision_path)
+ self.fs.file_delete(current_revision_path, ignore_non_exist=True)
+ self.fs.mkdir(current_revision_path)
+ self.fs.reverse_sync(from_path=current_revision_path)
+
+ shutil.rmtree(self.fs.path + _id)
+
self.db.replace(self.topic, _id, current_desc)
# Store a copy of the package as a point in time revision
revision_desc = dict(current_desc)
revision_desc["_id"] = _id + ":" + str(revision_desc["_admin"]["revision"])
self.db.create(self.topic + "_revisions", revision_desc)
+ fs_rollback = []
indata["_id"] = _id
self._send_msg("edited", indata)
finally:
if file_pkg:
file_pkg.close()
+ for file in fs_rollback:
+ self.fs.file_delete(file, ignore_non_exist=True)
def get_file(self, session, _id, path=None, accept_header=None):
"""
)
self.assertEqual(admin["usageState"], "NOT_IN_USE", "Wrong usage state")
storage = admin["storage"]
- self.assertEqual(storage["folder"], did, "Wrong storage folder")
+ self.assertEqual(storage["folder"], did + ":1", "Wrong storage folder")
self.assertEqual(
storage["descriptor"], "package", "Wrong storage descriptor"
)
)
self.assertEqual(admin["usageState"], "NOT_IN_USE", "Wrong usage state")
storage = admin["storage"]
- self.assertEqual(storage["folder"], did, "Wrong storage folder")
+ self.assertEqual(storage["folder"], did + ":1", "Wrong storage folder")
self.assertEqual(
storage["descriptor"], "package", "Wrong storage descriptor"
)