Skip to content

Commit

Permalink
syncObject: delete 'coms-id' tag on new file if id already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
norrisng-bc committed Nov 19, 2024
1 parent e26ff32 commit fc8d362
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion app/src/services/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,43 @@ const service = {

// Case: not in COMS - insert new COMS object
else {
const objId = await service._deriveObjectId(s3Object, path, bucketId);
let objId = await service._deriveObjectId(s3Object, path, bucketId);
let existingComsId;
try {
existingComsId = await objectService.read(objId);
} catch {
// Derived object id not currently in use by COMS
}

// Object id in 'coms-id' S3 tag already in use in COMS:
// Delete the 'coms-id' tag on the new object,
// so that we don't attempt to re-use an existing COMS object id.
if (existingComsId) {
const sourceObject = await storageService.getObjectTagging({
filePath: path,
bucketId: bucketId
});

// Workaround for deleting just the 'coms-id' tag (S3 can only delete ALL tags on an object):
// Retrieve all tags, delete all tags on object, then re-add all tags except 'coms-id'.
const objectTags = sourceObject.TagSet.filter(
x => !sourceObject.TagSet.includes(x.Key) && x.Key != 'coms-id'
);
await storageService.deleteObjectTagging({
filePath: path,
bucketId: bucketId
});
const data = {
bucketId,
filePath: path,
tags: objectTags
};
await storageService.putObjectTagging(data);

// _deriveObjectId() doesn't care if it conflicts with existing coms-id's,
// so generate a new one after deleting the S3 tag
objId = uuidv4();
}

response = await objectService.create({
id: objId,
Expand Down

0 comments on commit fc8d362

Please sign in to comment.