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 15, 2024
1 parent e26ff32 commit 0b906ef
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/src/services/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,37 @@ const service = {
else {
const objId = await service._deriveObjectId(s3Object, path, bucketId);

// if `coms-id` already in use in COMS, delete the 'coms-id' tag on the new object first,
// so that we don't attempt to use a coms-id that's already in use.
try {
const existingComsId = await objectService.read(objId);
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 keys except 'coms-id'.
const objectTags = sourceObject.TagSet.filter(x => !sourceObject.TagSet.includes(x.Key) && x.Key != 'coms-id');

Check warning on line 192 in app/src/services/sync.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x)

This line has a length of 125. Maximum allowed is 120

Check warning on line 192 in app/src/services/sync.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x)

This line has a length of 125. Maximum allowed is 120

Check warning on line 192 in app/src/services/sync.js

View workflow job for this annotation

GitHub Actions / Unit Tests (20.x)

This line has a length of 125. Maximum allowed is 120

await storageService.deleteObjectTagging({
filePath: path,
bucketId: bucketId
});

const data = {
bucketId,
filePath: path,
tags: objectTags
};

await storageService.putObjectTagging(data);
}
} catch {
// no coms-id conflict, proceed as usual
}

response = await objectService.create({
id: objId,
name: path.match(/(?!.*\/)(.*)$/)[0], // get `name` column
Expand Down

0 comments on commit 0b906ef

Please sign in to comment.