Skip to content

Commit 8077409

Browse files
committed
Dont delete parent bucket during sync
1 parent fc0f8e8 commit 8077409

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/src/controllers/sync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const controller = {
120120

121121
/**
122122
* @function syncBucketRecords
123-
* Synchronizes (creates / prunes) COMS db bucket records for each 'directry' found in S3
123+
* Synchronizes (creates / prunes) COMS db bucket records for each 'directory' found in S3
124124
* Adds current user's permissions to all buckets
125125
* @param {object[]} Array of Bucket models - bucket records already in COMS db before syncing
126126
* @param {string[]} s3Keys Array of key prefixes from S3 representing 'directories'
@@ -132,8 +132,9 @@ const controller = {
132132
*/
133133
async syncBucketRecords(dbBuckets, s3Keys, parentBucket, currentUserParentBucketPerms, userId, trx) {
134134
try {
135-
// delete buckets not found in S3 from COMS db
136-
const oldDbBuckets = dbBuckets.filter(b => !s3Keys.includes(b.key));
135+
// delete child buckets not found in S3 from COMS db
136+
// note: leave parent bucket recoprd in database even if it is empty
137+
const oldDbBuckets = dbBuckets.filter(b => !s3Keys.includes(b.key) && b.bucketId !== parentBucket.bucketId);
137138
await Promise.all(
138139
oldDbBuckets.map(dbBucket =>
139140
bucketService.delete(dbBucket.bucketId, trx)

0 commit comments

Comments
 (0)